0

I have a custom post type 'packages' with multiple taxonomies; i.e. 'destination'

i.e. mysite.com/destination/new-zealand/

The post type 'packages' also has other taxonomies, i.e. 'difficulty'

I wish to filter these area pages; something like: mysite.com/destination/new-zealand/?difficulty=medium

Here is the WP_Query:

$term_id = "12"; //medium
$taxquery = array(     
    'posts_per_page' => 1,
    'post_type' => 'packages',
    'tax_query' => array(
        array(
            'taxonomy' => 'difficulty',
            'field' => 'term_id',
            'terms' => $term_id,
            'operator'=> 'IN'
        ))
 );
2
  • It seems to me that you want to combine two taxonomies and serveral terms with the AND operator in the query. For example, get packages with new-zealand in destination taxonomy AND medium in difficulty taxonomy. Can you clarify it?
    – cybmeta
    Feb 15, 2017 at 13:04
  • 1
    Yes that is correct, using the relation AND works! Feb 15, 2017 at 17:18

1 Answer 1

0
// 12 - difficulty
// destination
// get Id current taxonomy
$this_term = get_queried_object();

        $taxquery = array(     
            'posts_per_page' => 1,
            'post_type' => 'packages',    
                      'tax_query' => array(
                               'relation' => 'AND',
        array(
            'taxonomy' => 'difficulty',
            'field'    => 'id',
            'terms'    => array( 12 ),
        ),
        array(
            'taxonomy' => 'destination',
            'field'    => 'id',
            'terms'    => array( $this_term->term_id) // Id current taxonomy
        )
    )
        );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.