admin_url( 'admin-ajax.php' ) ) ); wp_enqueue_script( 'genre-ajax-js' ); wp_enqueue_style( 'style-css', plugin_dir_url( __FILE__ ) . 'style.css' ); } /* Public function get_genre_filters accepts two parameters * $post_type : the post type slug to query * $taxo : the taxonomy slug to query * used for display the filters in your template (for example archive.php) like that : * $new_posts_filter = new Ajax_Filter_Posts(); * echo $new_posts_filter->get_genre_filters('post', 'category'); */ public function get_genre_filters($post_type, $taxo) { $terms = get_terms($taxo); $filters_html = false; if( $terms ): $filters_html .= '
'; $filters_html .= ''; $filters_html .= ''; foreach( $terms as $term ) { $term_id = $term->term_id; $term_name = $term->name; $filters_html .= ''.$term_name.''; } $filters_html .= 'Tous'; $filters_html .= '
'; return $filters_html; endif; } /* Public function ajax_genre_filters * Ajax call construct loop and results */ public function ajax_genre_filter() { $query_data = $_GET; $post_type = (isset($query_data['post_type'])) ? $query_data['post_type'] : false; $taxo = (isset($query_data['taxo'])) ? $query_data['taxo'] : false; $genre_terms = (isset($query_data['genres'])) ? explode(',',$query_data['genres']) : false; $tax_query = ($genre_terms) ? array( array( 'taxonomy' => $taxo, 'field' => 'id', 'terms' => $genre_terms ) ) : false; $search_value = (isset($query_data['search']) ) ? $query_data['search'] : false; $paged = (isset($query_data['paged']) ) ? intval($query_data['paged']) : 1; $book_args = array( 'post_type' => $post_type, 's' => $search_value, 'posts_per_page' => 15, 'tax_query' => $tax_query, 'paged' => $paged ); $book_loop = new WP_Query($book_args); // here place your own loader echo '
'; if( $book_loop->have_posts() ): while( $book_loop->have_posts() ): $book_loop->the_post(); global $post; setup_postdata($post); get_template_part( 'loop-templates/content', $post_type ); endwhile; ?> '; $big = 999999999; echo paginate_links( array( 'base' => esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, $paged ), 'total' => $book_loop->max_num_pages ) ); echo ''; ?>