WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] category__and not working after 3.1 update (11 posts)

  1. ajsadeh
    Member
    Posted 3 years ago #

    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.

  2. Matt
    Member
    Posted 3 years ago #

    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.

  3. ajsadeh
    Member
    Posted 3 years ago #

    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!

  4. ajsadeh
    Member
    Posted 3 years ago #

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

  5. ajsadeh
    Member
    Posted 3 years ago #

    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.

  6. scribu
    Member
    Posted 3 years ago #

    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:

    http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/comment-page-1/#comment-7146

  7. ajsadeh
    Member
    Posted 3 years ago #

    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

  8. shagen
    Member
    Posted 3 years ago #

    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!

  9. shagen
    Member
    Posted 3 years ago #

    scribu answered my last posts question at the following URL...

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

  10. drale2k
    Member
    Posted 3 years ago #

    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

  11. drale2k, please make a new topic.

Topic Closed

This topic has been closed to new replies.

About this Topic