WordPress.org

Ready to get started?Download WordPress

Forums

HELP! wp query SELECT multiple post_type with multiple taxonomies (2 posts)

  1. ad33lx
    Member
    Posted 1 year ago #

    Hi,
    I have two post_type
    1. post (default)
    2. coupon

    Taxonomies (category) for post: first_cate, second_cate, third_cate
    Taxonomies (coupon_category) for coupon: type_a,type_b,type_c

    Now I have two question
    1. I want to select "posts" (post_type='post') from only two categories (first_cate, second_cate) but show all coupons (post_type='coupon') from coupon_category

    2. I want to select "posts" (post_type='post') from only two categories (first_cate, second_cate) and show selected coupons (post_type='coupon') from two categories "type_a", "type_c"

    (Note: taxonomy for coupons is 'coupon_category')

  2. vtxyzzy
    Member
    Posted 1 year ago #

    I can't test this, but queries like this should be close to what you want:

    $args = array(
       'ignore_sticky_posts' => 1,
       'posts_per_page' => -1,
       'post_type' => array('post','coupon'),
       'tax_query' => array(
          'relation' => 'OR',
          array(
             'taxonomy' => 'category',
             'field' => 'slug',
             'terms' => array('first_cate', 'second_cate'),
             'include_children' => false,
             'operator' => 'IN'
          ),
          array(
             'taxonomy' => 'coupon_category',
             'field' => 'slug',
             'terms' => array('type_a', 'type_b', 'type_c'),
             'operator' => 'IN'
          )
       )
    );
    query_posts($args);

Topic Closed

This topic has been closed to new replies.

About this Topic