Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // AJAX Filter
  2. function filter_products() {
  3.  
  4. if( isset( $_POST['names'] ) && isset( $_POST['flower_colors'] ) && isset( $_POST['leaf_colors'] ) )
  5. $args = array(
  6. 'post_type'=> 'portfolio',
  7. 'posts_per_page' => -1,
  8. 'orderby' => 'title',
  9. 'order' => 'ASC',
  10. 'tax_query' => array(
  11. 'relation' => 'AND',
  12. array(
  13. 'field' => 'term_id',
  14. 'taxonomy' => 'tag_names',
  15. 'terms' => $_POST['names'],
  16. ),
  17.  
  18. array(
  19. 'field' => 'term_id',
  20. 'taxonomy' => 'tag_flower_colors',
  21. 'terms' => $_POST['flower_colors'],
  22. ),
  23.  
  24. array(
  25. 'field' => 'term_id',
  26. 'taxonomy' => 'tag_leaf_colors',
  27. 'terms' => $_POST['leaf_colors'],
  28. ),
  29. ),
  30. );
  31.  
  32. $query = new WP_Query( $args );
  33.  
  34. if( $query->have_posts() ) :
  35. while( $query->have_posts() ): $query->the_post();
  36. echo get_template_part( '/page-element-assortiment' );
  37. endwhile;
  38. wp_reset_postdata();
  39.  
  40. else :
  41. // echo '<p style="text-align: center;"></p>';
  42. endif;
  43.  
  44. die();
  45.  
  46. }
  47.  
  48. add_action('wp_ajax_myfilter', 'filter_products');
  49. add_action('wp_ajax_nopriv_myfilter', 'filter_products');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement