Support » Themes and Templates » Sticky posts included in category_and filter

  • If you are trying to filter posts in a custom loop using category_and, note that sticky posts will appear in this loop unless you filter them out as well.

    I just spent several very confused hours trying to figure this out.

    I was trying to limit the posts to only those that were in both category x and category y, but other posts not in either category kept showing up. Yup, they were sticky posts.

    They way to get rid of them – the way I know – is to send the following to wp_query:

    argument ignore_sticky_posts' => 1

    So it might look like this:

      args = array(
    	'ignore_sticky_posts' => 1,
    	'category__and'=> '456','626' )
      $wp_query = new WP_Query( $args ); // filter results
      while ($wp_query->have_posts()) : $wp_query->the_post();
    Do stuff...
    <?php endwhile; ?>

    Hope this helps someone avoid a bit of pain and suffering.

  • The topic ‘Sticky posts included in category_and filter’ is closed to new replies.