Support » Fixing WordPress » query_posts no longer working in 3.1

  • Resolved jrue


    Hi all,

    We were using query_posts function call that worked fine in 3.0.5 but chokes on 3.1. I was wondering is anyone had similar issues. I’ve redacted the code to the main part that we seem to have trouble with:

    // Don't include articles from the front featured category in our main front feed b/c there could be duplicates
    query_posts( array('category__in' => array($front_category_to_use), 'category__not_in' => array($front_featured_category_to_use) ) );
    // Store front features in a sepreate loop
    $featuredfrontposts = new WP_Query( array('category__and' => array($front_category_to_use, $front_featured_category_to_use) ) );
    $featuredfrontposts_ids = array();
    while ($featuredfrontposts->have_posts()){
             $featuredfrontposts_ids[] = get_the_ID();

    I can’t begin to tell you all how helpful you are. Thank you so much for any help anyone can provide!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I figured it out finally. If anyone else has this issue, here is what I had to change:

    query_posts( array('category__in' => array($front_category_to_use), 'category__not_in' => array($front_featured_category_to_use) ) );

    This query_posts no longer resulted in posts. Instead, I had to use the taxonomy parameters which became the following:

    $cptaxquery['tax_query'] = array(
    				'taxonomy' => 'category',
    				'terms' => array($front_category_to_use),
    				'field' => 'id',
    				'operator' => 'IN'
    				'taxonomy' => 'category',
    				'terms' => array($front_featured_category_to_use),
    				'field' => 'id',
    				'operator' => 'NOT IN'

    If anyone is stuck on this, here is the codex documentation on taxonomy. It doesn’t make it clear why this works in 3.1 as oppose to the older method.

    Hi, I had this same problem, and for some reason.

    The main issue for me, it seems (maybe on account of wordpress 3.1), is that the posts were in multiple categories, not just the one i want to exclude. If the post is JUST in the one I wanted to exclude, then all the excluding plugins, and basic fixes seem to work. But in my situation, this is the query_posts that worked for me! Finally!

    I am excluding category 28, and including category ‘brands’.

    <?php query_posts( array( ‘category__not_in’ => array(28), ‘category_name’ => ‘brands’, ‘posts_per_page’ => ’12’, ‘paged’ => $paged, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ) );?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts no longer working in 3.1’ is closed to new replies.