I have a problem with Yoast and displaying my primary category alongside rest of the posts from that category.

Let's say I have 4 posts, all of them are lorem category and one post has set lorem as primary category. Currently the lorem category page (/category/lorem) displays only the three posts that aren't set as primary of its category.

I have in my category.php a simply WP query:

<?php $current_category = single_cat_title('', false); ?>

  $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

  $args = array(
    'category_name' => $current_category,
    'paged' => $paged

  $query = new WP_Query($args);

<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
  /* do stuff */
<?php endwhile; endif; ?>

<?php previous_posts_link(); ?>
<?php next_posts_link(); ?>

How can I modify the current WP query to also include the primary category alongside with pagination?


1 Answer 1


I'm not sure this will fix it, but maybe try using the current category slug for the $current_category variable, instead of single_cat_title(), like so:

   $term = get_queried_object();
   $current_category = $term->slug;

This might help because the category_name parameter in WP_Query, despite its name, should be the term slug. single_cat_title() returns the displayed category title, not slug.

  • Nice, seems to work. Tnx! Will this also work with pagination?
    – Vucko
    Jun 14, 2019 at 6:35
  • Don't know why it wouldn't work with pagination @Vucko - let us know if it doesn't. :)
    – Michelle
    Jun 14, 2019 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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