WordPress.org

Ready to get started?Download WordPress

Forums

Sticky posts included in category_and filter (1 post)

  1. cemery
    Member
    Posted 3 years ago #

    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:

    <?php
      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.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by cemery
  • This topic is not a support question
  • WordPress version: 3.1