WordPress Query Posts Taxonomy

I currently have a checkbox based search and filter on my wordpress site.

Basically it works using this wp_query

Read More
$queryObject = new WP_Query(array("post_type"=>'toy','posts_per_page'=>999999, 
    'category__and' => $_POST['myListOfCategories']));

I want to move away from using categories (as it’s making using the blog a pain)

So I’ve set everything up using custom taxonomies now and notice there is no “taxonomy__and”.

Does anyone know of a way to use WP_Query to search for posts using taxonomies in the same way category__and and works?

e.g. I pass multiple taxonomy id’s and it only returns posts which have all of them linked.

Related posts

Leave a Reply

3 comments

  1. You have pass multiple taxonomy in Query_posts in WordPress

    See below URL It is very help full to you:-

    https://wordpress.stackexchange.com/questions/25999/how-to-pass-url-parameters-for-advanced-taxonomy-queries-with-multiple-terms-for

    https://wordpress.stackexchange.com/questions/10713/wp-3-1-getting-tax-query-to-work-in-query-posts

    Query multiple custom taxonomy terms in WordPress 2.8?

    or try it

    query_posts( array(
      'tax_query' => array(
        array(
          'taxonomy' => 'tax1',
          'field' => 'slug',
          'terms' => array('term1', 'term2'),
          'operator' => 'OR'
        ),
        array(
          'taxonomy' => 'tax2',
          'field' => 'slug',
          'terms' => array('term3', 'term4'),
          'operator' => 'AND'
        ),
    ) );
    
  2. With the help of the other posters here is the final answer to my question:

    $queryObject = new WP_Query(array("post_type"=>'toy','posts_per_page'=>10,'tax_query' => array(
            array(
                'taxonomy' => 'toy_cats',
                'field' => 'id',
                'terms' =>  array(14,20,39,42),
                'operator' => 'AND' )
        )));
    

    The above code will only show posts that have the “toy” post type, is in the taxonomy “toy_cats” and is is assigned to ALL the following term id’s 14 AND 20 AND 39 AND 42

    Hope this helps someone else.