0

i have a custom post type called 'events', it has a taxonomy named 'category' structured this way:

hotels (parent)
-1 star (child)
-2 stars (child)
-3 stars (child)

location (parent)
-loc1 (child)
-loc2 (child)
-loc3 (child)

how do i filter, for example, only the events that belong to 1 star and, at the same time, to loc1 (basically the intersection of 1 star and loc1)?

1
  • Hi Andrellibus, could you provide more details on what you've tried already (and why it didn't work)? – kraftner Jun 13 '14 at 16:29
0

You can use tax_query and use the AND condition:
Reference: WP_Query under Taxonomy Parameters

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'hotels',
            'field' => 'slug',
            'terms' => array( '1 Star' )
        ),
        array(
            'taxonomy' => 'location',
            'field' => 'slug',
            'terms' => array( 'loc1' )
        )
    )
);
$query = new WP_Query( $args );
0

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.