Site icon Hip-Hop Website Design and Development

The right way to filter customized submit sort by a number of Taxonomies

On the mission there’s a filter:

It ought to filter the customized submit ty recipes. Chosen gadgets are checkboxes. So, a number of values for filtering may be chosen at any time. However in my case, filtering works solely on one chosen factor. For instance, I selected ‘Lorem inpus1’ the recipes have been filtered by it. Now I select another factor ‘Lorem inpus3’ for instance and former outcomes eliminated. Right here is my code. I feel the reason being in it, however I can’t remedy this problem.

add_action('wp_ajax_myfilter', 'vicso_filter_function'); // wp_ajax_{ACTION HERE}
add_action('wp_ajax_nopriv_myfilter', 'vicso_filter_function');


perform vicso_filter_function(){
   //I feel drawback is right here all each time once I choose, the perform takes a brand new worth
   $products_filter = $_POST['products'];
   $types_food_filter = $_POST['types_food'];

   if( isset( $products_filter ) && !empty( $products_filter) ){
    $products_data = array(
        'taxonomy' => 'merchandise',
        'phrases' => $products_filter
    );

 } else{
    $products_filter = '';
 }

 if( isset(  $types_food_filter ) && !empty(  $types_food_filter ) ){
    $types_food_data = array(
        'taxonomy' => 'types_food',
        'phrases' =>  $types_food_filter
    );
  } else{
    $types_food_filter = '';
  }

  $args = array (
    'post_type' => 'recipes',
    'posts_per_page' => -1,
    'order' => 'DESC',
    'tax_query' => array(
        $products_data,
        $types_food_data
    )
  );

  $recipes = new WP_Query( $args );

}

I don’t assume the rationale could possibly be the javascript code, however right here is the code that I name the perform above.

$('#recipes-filter').change(perform(){

let filter = $('#recipes-filter');

jQuery.ajax({
    url:filter.attr('motion'),
    knowledge:filter.serialize(),
    sort:filter.attr('technique'),
    success:perform(knowledge){
        jQuery('#default-recipes-content').disguise();
        jQuery('#response-recipes-content').html(knowledge);
    }
});
return false;

});