I have a problem with making something like taxonomy filter. My code is similar to this:
$args = array( 'post_type' => 'post', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'movie_genre', 'field' => 'slug', 'terms' => array( 'action', 'comedy' ), ), array( 'taxonomy' => 'actor', 'field' => 'id', 'terms' => array( 103, 115, 206 ), 'operator' => 'NOT IN', ), ), ); $query = new WP_Query( $args );
Okay. So basically I have a form with several select inputs. I have looped terms into every select input. When I select one and click Submit, it will send me to another page where are queryd products with this term (term is in product attributes). But when I select two values on the first page, the next page should show only these products what have both terms in it. That relation AND didn't work because if some selectbox was left empty the $GET value is empty and so the term is empty. My terms are made like that:
$car = $_GET["car"];
And then I put these variables into array like this:
array( 'taxonomy' => 'pa_my_taxonomy', 'field' => 'name', 'terms' => $car, ),
Address is like that:
All my taxonomys are in that array. So if I have AND there, it will take into account every variable from address bar and if some of them is empty but product have something there it won't query that product.
For simple version I need to make car tires select form where I can select car type, season, tire diamenter and so on. If I select car type ordinary car and season winter then it would show me only tires with these product attributes.