0
function viewevnts() { 
    ob_start();     
$query = ( get_query_var( 'query' ) ) ? get_query_var( 'query' ) : 1;
$args = array(
        'post_type' => 'events',
        'category_name' => 'en-events',
        'posts_per_page' => 5,
        'query' => $query
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
     // CPT content

endwhile;

     $big = 999999999;
     echo paginate_links( array(
          'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
          'format' => '?query=%#%',
          'current' => max( 1, get_query_var('query') ),
          'total' => $loop->max_num_pages,
          'prev_text' => '«',
          'next_text' => '»'
     ) );
     return  $data; 

}

add_shortcode('AllEvents','viewevnts'); // end 

i tried with above code items displaying but when i click on 2 page it will coming 404 error page. please help me on this.

  • Is there a reason you're using a shortcode and not just the standard post type archive template? – Jacob Peattie May 4 at 12:29
  • yes @JacobPeattie i'm using shortcode but all items are displaying as above code except the pagination is not working, i tired without shortcode & coming all data but when i click pagination <a> tag pagination it is coming same 404 error. – Vijay Kumar Gajam May 4 at 12:39
  • @JacobPeattie can you help me on this? – Vijay Kumar Gajam May 4 at 15:50
  • finally i cracked with flaviusmatis.github.com/simplePagination.js – Vijay Kumar Gajam May 13 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.