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); ?>
<?php
$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?
Thanks
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); ?>
<?php
$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?
Thanks
Share Improve this question asked Jun 13, 2019 at 15:20 VuckoVucko 1631 gold badge1 silver badge10 bronze badges1 Answer
Reset to default 1I'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.