0

I can pull the terms from a post to return only the Primary Category that Yoast SEO plugin provides.

But what I'd like to do is the following:

Query latest 1 post from category "x". But, the post returned has to have that category set as the Primary. It can't return the latest if that post has not marked that cat as primary.

2

Yoast SEO stores the primary term ID as the post meta field _yoast_wpseo_primary_{taxonomy}. Knowing this you can use a meta query to get all posts with primary category ID X:

$query = new WP_Query([
    'cat' => 'X', // Just in case Yoast data corrupted & post no longer attached to X term but primary meta remains
    'meta_query' => [
        [
            'key' => '_yoast_wpseo_primary_category',
            'value' => 'X',
        ]
    ],
]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.