Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_posts_for_pagination() {
- $html = '';
- $paged = ( $_GET['page'] ) ? $_GET['page'] : 1;
- $post_type = $_GET['posttype'];
- if ( empty($post_type) ) {
- return '';
- }
- if( filter_var( intval( $paged ), FILTER_VALIDATE_INT ) ) {
- $args = array(
- 'post_type' => $post_type,
- 'paged' => $paged,
- 'posts_per_page' => 4,
- 'post_status' =>'publish'
- );
- $loop = new WP_Query( $args );
- $post_count = $loop->found_posts;
- $max_num_pages = $loop->max_num_pages;
- if( $loop->have_posts() ) {
- while( $loop->have_posts() ) {
- $loop->the_post();
- $html .= 'your output'
- }
- wp_reset_query();
- }
- }
- echo $html;
- exit();
- }
- add_action( 'wp_ajax_pagination', 'get_posts_for_pagination' );
- add_action( 'wp_ajax_nopriv_pagination', 'get_posts_for_pagination' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement