Ajax Load more with custom wp_query?
-
Hi,
This plugin is amazing. I wonder if it offers the load more feature for a custom wp_query have the pagination active. Here is the basic custom wp_query that output post list.
// Shortcode [dy_ajax_posts] if ( ! function_exists('dy_ajax_posts_shortcode') ) { function dy_ajax_posts_shortcode( $atts ){ global $post; global $wp_query; ob_start(); if ( is_front_page() ) { $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1; } else { $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; } $args = array( 'post_type' => 'post', 'posts_per_page' => 2, 'paged' => $paged ); $query = new WP_Query($args); // The Loop if ($query->have_posts() ) : echo '<div class="post-container">'; while ( $query->have_posts() ) : $query->the_post(); // Do Stuff $title = get_the_title(); $permalink = get_the_permalink(); echo '<article class="post article"><a href="'.$permalink.'">'.$title.'</a></article>'; endwhile; if ( is_front_page() ) { echo '<div class="pagination" role="navigation" aria-label="Pagination">'; echo paginate_links(array( 'current'=>max(1,get_query_var('page')), 'total'=>$query->max_num_pages, )); echo '</div>'; } else { echo '<div class="pagination" role="navigation" aria-label="Pagination">'; echo paginate_links(array( 'total' => $query->max_num_pages, )); echo '</div>'; } wp_reset_postdata(); endif; echo '</div>'; $html = ob_get_clean(); return $html; } } add_shortcode('dy_ajax_posts', 'dy_ajax_posts_shortcode');
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Ajax Load more with custom wp_query?’ is closed to new replies.