0

i have a custom post type name 'business' and taxonomy 'business-category'. now i want to show posts for some specific terms suppost, term1, term2, term3 etc. The following code is working for me but for only one term.

  $args=array(
    'taxonomy' => 'business-category',
    'term' => 'term1',
    'post_type' => 'business',
    'orderby'=> 'rand',
    );
  query_posts($args);

I need to pass array of terms. When i try to pass array of terms instead of one term it not working :(

   $args=array(
    'taxonomy' => 'business-category',
    'term' => array('term1', 'term2', 'term3'),
    'post_type' => 'business',
    'orderby'=> 'rand',
    );
  query_posts($args);

I also want to know how can i show post if i want to show from multiple taxonomy as well.

Thanks!


Resolved:

the query args will be:

    $args=array(
            'tax_query' => array(
                          array(
                                'taxonomy' => 'business-category',
                                'field' => 'slug',
                                'terms' => array( 'bars', 'restaurants' )
                           )
          );

Thanks!

1

I believe the array will work using terms, rather than term (plural)

http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters

Has a lot of useful info for mutiple terms/multiple taxonomies

but basically look into the tax_query item, specifically AND or OR operators. It's all explained there pretty well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.