wp_query filtering problem tax_query
-
Hi!
I have a problem with my filtering method.
I have a form with multiple filtering options. I put these options in my url and I get them with GET. Except that if I put “All”, nothing is shown because then my category and my tag are equal to nothing.<?php if($_GET['category'] && !empty($_GET['category'])) { $category = $_GET['category']; } if($_GET['tag'] && !empty($_GET['tag'])) { $tag= $_GET['tag']; } ?><form action="<?php the_permalink(); ?>" method="get"> <label>Category:</label> <select name="category"> <option value="">ALL</option> <option value="men">Men</option> <option value="women">Women</option> </select> <label>Tag:</label> <select name="tag"> <option value="">ALL</option> <option value="Tag 1">Tag 1</option> <option value="Tag 2">Tag 2</option> </select> <button type="submit" name="">Filter</button> </form><?php $args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'product_cat' => $my_parent_category, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $category, 'compare' => 'LIKE', ), array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $tag, 'compare' => 'LIKE', ), ), );Is there a way to say; if $category or $tag is null, display all the category and tags?
Thanks
`
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘wp_query filtering problem tax_query’ is closed to new replies.