• I know that if you want to look up either of two tags you use:

    WP_Query("post_type=post&tag=tag1,tag2");

    If you want to do both you do:

    WP_Query("post_type=post&tag=tag1+tag2");

    But what if you want to do tag1+tag2 OR tag3+tag4? I tried this and it didn’t work:

    WP_Query("post_type=post&tag=tag1+tag2,tag3+tag4");

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter deltatango

    (@deltatango)

    and example of this is:

    tag=doctor+smallville,receptionist+smallville

    so only find doctors or receptionists in smallville

    Thread Starter deltatango

    (@deltatango)

    In case anyone stumbles across this, this is how I solved it. I had to use associative arrays. This was the code:

    $args = array('post_type'=>"post",
                         'posts_per_page'=>-1,
                         'tax_query'=>array(
    
     'relation' =>'AND',									                      array('taxonomy'=>'post_tag',
    'field'=>'slug',
    'terms'=>tag1,
    'operator'=>'IN'),
    
    													array('taxonomy'=>'post_tag',
    'field'=>'slug',												'terms'=>array('tag2','tag3'),
    'operator'=>'IN'))
    
    );			
    
    $thepages=new WP_Query($args);
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Two Taxonomy And/Or’ is closed to new replies.