Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //in functions.php
- function bar_2_share_scripts() {
- wp_enqueue_script('top-five-ajax-pagination', get_stylesheet_directory_uri() . '/assets/js/pagination.js', array('jquery'), microtime().'', true);
- global $wp_query;
- wp_localize_script( 'top-five-ajax-pagination', 'ajaxpagination', array(
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
- 'query_vars' => json_encode( $wp_query->query )
- ));
- }
- add_action( 'wp_enqueue_scripts', 'bar_2_share_scripts' );
- function bar_ajax_pagination() {
- $p_type = array('articles', 'post');
- $_POST['postType'] = $p_type;
- $paged = $_POST['page'];
- $ppp = 6;
- $do_not_duplicate[] = get_the_ID();
- $query_vars = [
- 'paged' => $paged,
- 'post_type' => $p_type,
- 'orderby' =>'date',
- 'order' => 'DESC',
- 'posts_per_page' => $ppp,
- 'post_parent' => 0,
- 'post__not_in' => $do_not_duplicate
- ];
- // $query_vars['paged'] = $_POST['page'];
- $posts = new WP_Query( $query_vars );
- $GLOBALS['wp_query'] = $posts;
- if( ! $posts->have_posts() ) {
- get_template_part( 'content', 'none' );
- }
- else {
- while ( $posts->have_posts() ) {
- $posts->the_post();
- get_template_part( 'template-parts/content', $_POST['postType'] );
- }
- // $posts->rewind_posts();
- wp_reset_query();
- }
- die();
- }
- add_action( 'wp_ajax_nopriv_ajax_pagination', 'bar_ajax_pagination' );
- add_action( 'wp_ajax_ajax_pagination', 'bar_ajax_pagination' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement