Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AJAX Filter
- function filter_products() {
- if( isset( $_POST['names'] ) && isset( $_POST['flower_colors'] ) && isset( $_POST['leaf_colors'] ) )
- $args = array(
- 'post_type'=> 'portfolio',
- 'posts_per_page' => -1,
- 'orderby' => 'title',
- 'order' => 'ASC',
- 'tax_query' => array(
- 'relation' => 'AND',
- array(
- 'field' => 'term_id',
- 'taxonomy' => 'tag_names',
- 'terms' => $_POST['names'],
- ),
- array(
- 'field' => 'term_id',
- 'taxonomy' => 'tag_flower_colors',
- 'terms' => $_POST['flower_colors'],
- ),
- array(
- 'field' => 'term_id',
- 'taxonomy' => 'tag_leaf_colors',
- 'terms' => $_POST['leaf_colors'],
- ),
- ),
- );
- $query = new WP_Query( $args );
- if( $query->have_posts() ) :
- while( $query->have_posts() ): $query->the_post();
- echo get_template_part( '/page-element-assortiment' );
- endwhile;
- wp_reset_postdata();
- else :
- // echo '<p style="text-align: center;"></p>';
- endif;
- die();
- }
- add_action('wp_ajax_myfilter', 'filter_products');
- add_action('wp_ajax_nopriv_myfilter', 'filter_products');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement