Support » Plugins and Hacks » Hacks » category__and not working after 3.1 update

  • Resolved ajsadeh

    (@ajsadeh)


    In a plugin on our site we have code as follows that displays posts that belong to two categories selected in a form.

    $args = array(
       'category__and' => array($_GET['neighbourhood'],$_GET['venueType']),
       'posts_per_page' => -1
       );
    query_posts($args);

    Until the 3.1 update the code worked fine. Now it produces zero results. I have confirmed that the strings are being passed the correct IDs.

    I see that a bug related to category__and was identified in this release and that the code has been changed… http://core.trac.wordpress.org/ticket/16157

    am I overlooking something or is there a bug in the core?

    Any help gratefully received.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Noticed the same when trying to use a custom function to remove posts from categories from showing up in the post output. It broke after the recent upgrade.

    Boyevul i think your problem is related to category exclusions that is described here http://core.trac.wordpress.org/ticket/16622 and fixed here http://wordpress.org/extend/plugins/hotfix/

    good luck 🙂

    my issue still outstanding though!

    This issue is being dealt with here – http://core.trac.wordpress.org/ticket/16730

    I updated my query to the following code:

    $mapSearchQajs['tax_query'] = array(
       array(
          'taxonomy' => 'category',
          'terms' => array($_GET['neighbourhood']),
          'field' => 'id',
       ),
       array(
          'taxonomy' => 'category',
          'terms' => array($_GET['venueType']),
          'field' => 'id',
       ),
       'posts_per_page' => -1
    );
    
    query_posts($mapSearchQajs);

    using the excellent advice at http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/

    This resolved the issue for me.

    Notice that ‘category__and’ doesn’t include posts assigned to children categories (neither in WP 3.1 or in WP 3.0), while the tax_query you’re currently using does.

    Does this have any relevance in your case?

    Also, does this work:

    $mapSearchQajs['tax_query'] = array(
       array(
          'taxonomy' => 'category',
          'terms' => array($_GET['neighbourhood'], $_GET['venueType']),
          'field' => 'id',
          'operator' => 'AND'
       )
    );
    
    query_posts($mapSearchQajs);

    PS: I already mentioned that ‘posts_per_page’ doesn’t have any effect there:

    WordPress 3.1: Advanced Taxonomy Queries

    Thanks – I fixed the ‘posts_per_page’, although strangely it was outputting all results when located there as well.

    The alternative code you provided did not produce the expected results. It produced many fewer or no results compared to the other tax_query code.

    The child category issue shouldn’t apply here – and the original query successfully used category__and on 3.0.5

    shagen

    (@shagen)

    In the tax_query part I am wanting to limit both of the arrays to only show posts with a certain tag but am not able to do so. Outside of that it all works. I have started a new post here if you would like to view the code that I have been struggling with. Thought that since you had experience with this code that you gentlemen would have insight on where to start or how to solve. Thanks for the time!

    shagen

    (@shagen)

    scribu answered my last posts question at the following URL…

    http://wordpress.org/support/topic/limit-multiple-categories-tax_query-by-tag-not-working

    Hey guys i still have that issue in WP 3.2 but the solutions you posted still not work for me.

    It worked in 3.1 although

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    Lead Plugin Wrangler

    drale2k, please make a new topic.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘category__and not working after 3.1 update’ is closed to new replies.