php - Wordpress tax_query "and" operator not functioning as expected -
i have custom post type of image custom taxonomy called image_tag (it's hierarchical categories). here examples of tags might used:
structure (id: 25) - house (id: 56) - skyscraper nature - animal - plant (id: 41)
so, want drill down through images selecting multiple tags in conjunction "and" operator. example, finding photos plants , houses.
$query_args = array( 'post_type' => 'image', 'tax_query' => array( array( 'taxonomy' => 'image_tag', 'terms' => array(41, 56), // ids of "plant" , "house" 'operator' => 'and', ), ), );
that works fine, problem begins when try include parent terms, example:
$query_args = array( 'post_type' => 'image', 'tax_query' => array( array( 'taxonomy' => 'image_tag', 'terms' => array(25, 41), // ids of "structure" , "plant" 'operator' => 'and', ), ), );
then no results. i'm guessing because i'm using "and" operator, wordpress doesn't include children of "structure" term. have idea how can work?
so should this:
'relation' => 'and', array( 'taxonomy' => 'image_tag', 'field' => 'term_id', 'terms' => array( 25 ), ), array( 'taxonomy' => 'image_tag', 'field' => 'term_id', 'terms' => array( 41 ), ), ),
Comments
Post a Comment