-
Notifications
You must be signed in to change notification settings - Fork 882
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
[Feature Request] REST API endpoint for pulling posts from primary category #6251
Comments
Thanks for requesting this enhancement. Unfortunately we're not able to implement this at short notice. Currently we're focusing on issues that affect many users. We've concluded that this enhancement is not needed by many users, therefore we are not able to implement this short-term. However, if more users are in need of this, we'll of course revisit this issue. |
Hello Yoast team! 👋🏻 For a recent project, I needed a way to request posts from the REST API matching the primary category of a particular post. I discovered this Issue and original solution provided by Chris above. However, I was able to query posts from the Primary Category by filtering the <?php
add_filter(
'rest_post_query',
function ( $args, $request ) {
if ( ! empty( $request['primary_category'] ) ) {
$args['meta_query'] = [
[
'key' => '_yoast_wpseo_primary_category',
'value' => $request['primary_category'],
'compare' => '=',
],
];
}
return $args;
},
10,
2
); While I personally do not feel this needs to belong in Yoast WordPress-SEO plugin, if is added to the plugin, it should be extended in a different manner to match the ability to query from different taxonomies based on the Happy to submit a patch, if Yoast SEO team determines this is acceptable functionality for the plugin. |
Looked for a function or api method to pull posts that have a specific primary category
I wrote up a blog article on how I pulled this off and Joost asked me to open an issue. My solution works, it's slightly custom to my specific needs by pulling in children as well, but seems to do the trick and easy to adjust.
https://whoischris.com/yoast-primary-category-endpoint-wp-rest-api/
https://gist.github.com/ChrisFlannagan/a6f63a02ea16268a25bc5d386e9ac63a#file-primary-cat-php
The text was updated successfully, but these errors were encountered: