I have this query;

$posts = new WP_Query(array(
            'post_type' => 'post',
            'posts_per_page' => 5,

Which correctly places sticky posts at the beginning. However, when I add a taxonomy query like so;

$posts = new WP_Query(array(
            'post_type' => 'post',
            'posts_per_page' => 5,
            'tax_query' => array(
                        'taxonomy' => 'category',
                        'field' => 'slug',
                        'terms' => 'news'

Sticky posts will no longer be prepended in the results. I have tried including the ignore_sticky_posts => 0 parameter but I have had no success.

How can I get sticky posts working with a taxonomy query? And yes, my sticky posts belongs to that term.

  • 3
    Possible duplicate of WP_Query: Why is sticky post not first item in loop? – Pieter Goosen Jun 5 '16 at 18:44
  • @Sumit sticky posts does work with custom loops, it just depends on the exact arguments passed to WP_Query ;-) – Pieter Goosen Jun 5 '16 at 18:49
  • 1
    @Sumit with the arguments passed in the first block, this causes is_home internally to0 be set to true. Remember, the arguments passed to a query decides the value of the condional tags – Pieter Goosen Jun 5 '16 at 18:57
  • Weird, because sticky posts are definitely working for me in that first query. If I unsticky in the WP Admin, the post falls back to its normal position. Otherwise when sticky, it's at the top. – somebodysomewhere Jun 5 '16 at 18:58
  • @PieterGoosen I am sorry you mean is_home() will be true for first query in OP ? – Sumit Jun 5 '16 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.