WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] query_posts no longer working in 3.1

[Resolved] query_posts no longer working in 3.1

  • 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->the_post();
             $featuredfrontposts_ids[] = get_the_ID();
    }
    $featuredfrontposts->rewind_posts();

    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(
    		array(
    				'taxonomy' => 'category',
    				'terms' => array($front_category_to_use),
    				'field' => 'id',
    				'operator' => 'IN'
    		),
    		array(
    				'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 ‘[Resolved] query_posts no longer working in 3.1’ is closed to new replies.
Skip to toolbar