WP_Query pagination page>2 not found(404 error)
-
Hi, guys!
I have a terrible problem with my wp_query pagination for custom post type records .(I use code above to do my custom post loop output:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $arg=array( 'posts_per_page' => 5, 'post_type' => 'doctor', 'post_status' => 'publish', 'paged' => $paged ); $arg=apply_filter($arg); $posts = new WP_Query($arg); ?> <div class="row sort"> <?php get_template_part('includes/sort') ?> </div> <?php if($posts->have_posts()) { while ($posts->have_posts()) { $posts->the_post(); echo get_template_part('content', 'doctor'); } } wp_reset_postdata(); if(function_exists('custom_pagination')) custom_pagination($posts); ?>There is function to output my custom pagination by custom wp_query:
function custom_pagination($posts) { $big = 999999999; $pages = paginate_links(array( 'base' => str_replace($big, '%#%', get_pagenum_link($big, false)), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $posts->max_num_pages, 'type' => 'array', 'prev_next' => TRUE, 'prev_text' => '«', 'next_text' => '»', )); if (is_array($pages)) { $current_page = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged'); echo '<ul class="pagination">'; foreach ($pages as $i => $page) { if ($current_page == 1 && $i == 0) { echo "<li class='active'>$page</li>"; } else { if ($current_page != 1 && $current_page == $i) { echo "<li class='active'>$page</li>"; } else { echo "<li>$page</li>"; } } } echo '</ul>'; } }So, I create my pagination in this way.
..but I cant to change my current page to 2,3 or another, except – first page. I have got 404 error and I dont know why.Any ideas?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘WP_Query pagination page>2 not found(404 error)’ is closed to new replies.