0

I have custom post type called items and added custom taxonomies type and sub-type.

enter image description here

I like to query posts from both post and items post type that has art as either Tags or Sub type.

Below is what I currently have and it's not working.

$args = array(
    'post_type'         => array('items', 'post'),
    'posts_per_page'    => 4,
    'tax_query' => array(
        'relation' => 'OR',
        array(
            'taxonomy' => 'sub-type',
            'field'    => 'name',
            'terms'    => 'art',
        ),
        array(
            'taxonomy' => 'tag',
            'field'    => 'name',
            'terms'    => 'art',
        ),
    )
);
7
  • The built-in tag taxonomy is post_tag.
    – Milo
    Commented Jan 26, 2016 at 23:14
  • To add to @Milo You should avoid using the name parameter in a tax_query. Due to crappy sanitation, the tax_query fails in an really bad unexpected way when a term name has more than one word and/or special characters Commented Jan 27, 2016 at 4:13
  • @Milo u meant using post_tag instead of tax_query? It does not seem to be working in my situation...
    – Ohsik
    Commented Jan 27, 2016 at 18:41
  • no, 'taxonomy' => 'post_tag' inside the tax_query for built-in tag taxonomy.
    – Milo
    Commented Jan 27, 2016 at 18:59
  • @Milo thank you for the quick response! yes, that seems to be working!
    – Ohsik
    Commented Jan 27, 2016 at 19:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.