admin管理员组文章数量:1434934
I would like to show sticky posts at the top of an archive list for a specific category on the top page as well as on archive pages. I've been Googling for a working solution and found a few clues similar to this:
if(!empty(get_option('sticky_posts'))){
$args = array(
'posts_per_page' => -1,
'posts__in' => get_option('sticky_posts'),
'category_name' => 'EVENTS'
);
$catquery = new WP_Query($args);
}
The above code only works if 'category_name' => 'EVENTS'
is commented out, so it seems as if you cannot show sticky posts at the top of the archive list as long as a category is called. Although some wrote something like 'WordPress can only show sticky posts on the front page.', but this does not seem to be the case making me terribly confused.
Someone please help me work this out.
Thank you in advance.
I would like to show sticky posts at the top of an archive list for a specific category on the top page as well as on archive pages. I've been Googling for a working solution and found a few clues similar to this:
if(!empty(get_option('sticky_posts'))){
$args = array(
'posts_per_page' => -1,
'posts__in' => get_option('sticky_posts'),
'category_name' => 'EVENTS'
);
$catquery = new WP_Query($args);
}
The above code only works if 'category_name' => 'EVENTS'
is commented out, so it seems as if you cannot show sticky posts at the top of the archive list as long as a category is called. Although some wrote something like 'WordPress can only show sticky posts on the front page.', but this does not seem to be the case making me terribly confused.
Someone please help me work this out.
Thank you in advance.
Share Improve this question edited Apr 2, 2019 at 5:31 phatskat 3,1741 gold badge18 silver badges26 bronze badges asked Apr 2, 2019 at 2:40 FizzlerFizzler 757 bronze badges1 Answer
Reset to default 0As per documentation for WP_Query()
, category_name
should be category slug
.
So replace EVENTS
with the slug of category EVENTS
'category_name' => 'events' // Assuming that 'events' is slug of category `EVENTS`
OR
'cat' => 5' // Replace 5 with id of of category `EVENTS`
I hope this helps.
本文标签: categoriesSticky posts not working when a specific category is set
版权声明:本文标题:categories - Sticky posts not working when a specific category is set 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745636785a2667608.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论