admin管理员组文章数量:1426644
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.
本文标签: Yoast primary category query modification
版权声明:本文标题:Yoast primary category query modification 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745404280a2657179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论