Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting _yoast_wpseo_primary_* via WP Rest api meta fields #15750

Open
zanona opened this issue Jul 29, 2020 · 6 comments
Open

allow setting _yoast_wpseo_primary_* via WP Rest api meta fields #15750

zanona opened this issue Jul 29, 2020 · 6 comments

Comments

@zanona
Copy link

zanona commented Jul 29, 2020

I would like to be able to POST to /wp-json/wp/v2/:post_type/:id with a payload such:

{
    "title": "Test",
    "meta": {"_yoast_wpseo_primary_product_category": 63 },
    "product_categories": [ 58, 59, 63 ],
    ...
}

and with that, setting the primary category of a post, as expected.

@Djennez
Copy link
Member

Djennez commented Jul 29, 2020

Well, there's also a request to get posts based on the primary. So it isn't strange to have away to set those ID's via the API either.

@zanona
Copy link
Author

zanona commented Jul 29, 2020

Nice! Would you guys recommend a possible workaround at the moment where we can set the primary category along with the request or as a side effect of the API action?

@zanona
Copy link
Author

zanona commented Jul 30, 2020

OK, just following here with a workaround which seems to work fine.
By manually creating the meta field (in my case: _yoast_wpseo_primary_product_category) on the CPT, allows me to set its value through WordPress API and also has the expected result adjusting the dropdown on the post edit page (it seems to take a while and needs cleaning browser cache for it to refresh accordingly, though). But so far it has worked for my use case.

@Bruce-ST
Copy link

OK, just following here with a workaround which seems to work fine.
By manually creating the meta field (in my case: _yoast_wpseo_primary_product_category) on the CPT, allows me to set its value through WordPress API and also has the expected result adjusting the dropdown on the post edit page (it seems to take a while and needs cleaning browser cache for it to refresh accordingly, though). But so far it has worked for my use case.

You meant CPT, does this work for normal Posts as well?

@zanona
Copy link
Author

zanona commented Nov 16, 2020

I haven't tried on regular posts, I'm afraid. But I can't think of any limitation which would prevent this from working?

@djoo
Copy link

djoo commented Feb 11, 2021

Hi guys,
Any news about the possibility to do this ?

{
    "title": "Test",
    "meta": {"_yoast_wpseo_primary_product_category": 63 },
    "product_categories": [ 58, 59, 63 ],
    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants