categories - Sticky posts not working when a specific category is set

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 ar

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

As 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745636786a4637443.html

相关推荐

  • categories - Sticky posts not working when a specific category is set

    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 ar

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信