Custom Query Not Working with Taxonomies
-
Hello all,
I’m really stuck on a problem and I’m not understanding it at all. I’ve read up on how to use taxonomy queries and it sounds like based on my data structure, this should work:
I want to show all equipment items that have a category slug = ‘type1’ and a location slug = ‘location1’. Here is how my query is structured:
$location = 'location1'; $type = 'type1'; // Build the args $args = array( 'post_type' => 'equipment', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => -1, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array( $type ) ), array( 'taxonomy' => 'locations', 'field' => 'slug', 'terms' => array( $location ) ) ) ); // Query the posts $posts = query_posts( $args );
The issue here is that the query returns ALL of the equipment items that belong to the location given, but it ignores the category “type” specification. I can’t figure out why because based on all of the examples I’ve read, this should work just fine.
Any ideas? Thanks in advance!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Query Not Working with Taxonomies’ is closed to new replies.