0

Is there any way I can edit the below so that it will only get posts from the category if the post has been assigned as the primary category that Yoast SEO adds?

I only want to get posts that have been assigned to this category and that it has been marked as the primary category.

<?php
 $args = array(
 'posts_per_page'   => 6,
 'offset'           => 0,
 'orderby'          => 'date',
 'order'            => 'DESC',
 'post_type'        => 'post',
 'post_status'      => 'publish',
 'suppress_filters' => true,
 'tax_query' => array(
 array(
      'taxonomy' => 'news-category',
      'field' => 'slug',
       'terms' => 'offers'
       )
    )
);
$posts = get_posts( $args ); 

1 Answer 1

1

Managed to sort it, the primary category is added as post meta to the post, therefore you can pass through the following arguments:

'meta_key'     => '_yoast_wpseo_primary_news-category',
'meta_value'   => 1179,

Note: your meta key will be different since this is a custom taxonomy that I have set up, if you print the get_post_meta for your posts, you should be able to see what the meta key is...

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