I'm having trouble querying posts that have multiple tags from a custom taxonomy. For example, if I have a post called "Strawberry Splice," it has the Meal Types (custom taxonomy) "Gluten Free" and "Beverages."
When I filter the posts to look for "Gluten Free," "Strawberry Splice" shows up but when I search for "Beverages," there aren't any results. My query is only looking at the first term.
Take a look at http://jimalie.com.au/recipes/
This is my partial code to generate the custom taxonomy:
$args = array( 'labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_tagcloud' => true, 'show_admin_column' => false, 'hierarchical' => false, 'rewrite' => true, 'query_var' => true ); register_taxonomy( 'meal_types', array('recipes'), $args );
This is my code for the query:
$mealtype = $_POST['mealtype']; $args = array('post_type' => 'recipes', 'meal_types' => $mealtype, 'paged' => $paged);
I get $mealtype from the dropdown that is dynamically populated:
$terms = get_terms( 'meal_types' ); $count = count($terms); if ($count > 0) { foreach ($terms as $term) { ?> <option value="<?php echo $term->name; ?>" <?php if($_POST['mealtype'] == $term->name) { echo 'selected'; } ?>><?php echo $term->name; ?></option> <?php } }
My query:
$wp_query = new WP_Query( $args ); if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
The whole template's code: http://pastebin.com/5e07FMJm
How do I get it to look at all the terms?
$mealtype
and how is it formatted? Also, how are you actully querying the posts -WP_Query()
,get_posts()
orquery_posts()
?