Apologies — new to the stackexchange and actually posted this over in Stack Overflow because I didn’t know there was a WP specific joint.
My issue–
What I Have: I’ve got the code for a working events list. There’s a single custom post (events) and three taxonomies (location, month, type). The following code lists future events and orders them by a custom field (start_date). The events list is also sortable by taxonomy. For instance, you can look at just events in December (month) or for events by location (Montana).
What I Can’t Figure Out: How to sort lists by two different taxonomies. For instance: Events in December (month) that are also in Montana (location). It just seem to pick one or the other.
Other Info: When using the standard WordPress loop, not the custom one below, there’s no problem with multiple queries with this CPT and taxonomies, but of course, it posts every event that ever happened, including the ones in the past.
Also, this is my first wp_query, so I’m hoping it’s something obvious.
File: (archives-events.php)
<?php
$today = date('Ymd');
$my_query = new WP_Query( array(
'post_type' => 'events',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'location',
'terms' => $term,
),
array(
'taxonomy' => 'month',
'terms' => $term,
),
array(
'taxonomy' => 'type',
'terms' => $term,
)),
'posts_per_page' => 10,
'meta_compare' => '>',
'meta_value' => $today,
'orderby' => 'meta_value',
'meta_key' => 'start_date',
'order' => 'ASC',
'paged'=> $paged,
)); ?>
<?php if ( $my_query->have_posts() ) : while ($my_query->have_posts() ) : $my_query->the_post();?>
<!-- OUTPUT OF QUERY -->
<?php endwhile;
wp_reset_postdata();
endif; ?>
Here’s a function to do a query with multiple taxonomies:
And here’s an example on how i used it in a past project:
The
produtos
is the custom post type upon which i’m doing the search,prod-categoria
andprod-cols
are two custom taxonomies andblocos
and7-c
are two terms from the previous custom taxonomies.Hope that helps.
OBS1; the function is not from me, but probably from an old post here.
OBS2; this was funcional on a 3.1.2 installation.