Ajax filter not querying correctly
-
I have two list of checkboxes, “Animal” and “Colour”
I’ve written ajax query to filter them down, when I select dog and cat, they only show. However I say I want colour grey, it shows all animals as well that relate to grey.
Below is my WP query, I can’t work out why it doesn’t filter right….
// Getting the ajax data: // An array of keys("name")/values of each "checked" checkbox $experimentChoices = $_POST['experiment']; $mediaChoices = $_POST['media']; $meta_query = array( 'relation' => 'OR' ); foreach($mediaChoices as $Key=>$Value){ if(count($Value)){ foreach ($Value as $Inkey => $Invalue) { $meta_query[] = array( 'key' => $Key, 'value' => $Invalue, 'compare' => '=' ); } } } foreach($experimentChoices as $Key=>$Value){ if(count($Value)){ foreach ($Value as $Inkey => $Invalue) { $meta_query[] = array( 'key' => $Key, 'value' => $Invalue, 'compare' => '=' ); } } } $args = array( 'post_type' => 'downloads', 'meta_query' =>$meta_query ); $query = new WP_Query($args); if( $query->have_posts() ) : while( $query->have_posts() ): $query->the_post(); get_template_part( 'template-parts/filter-content' ); endwhile; wp_reset_query(); else : // wp_send_json($query->posts); print '<div class="post_content"><p>Sorry no publications found</p></div>'; endif; die();
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Ajax filter not querying correctly’ is closed to new replies.