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.