I hate answering my own question but yes I found the solution. The problem was with the custom post type slug "schedules" was had the same slug as the page name "schedules" I think that was conflicting, well I don't think it should but anyways.
Strange pagination behavior giving white page
-
08-07-2023 - |
Question
I' am using WordPress pagination. I have used this code on my other pages and it's working fine in there, but on this page "schedules" when I try to goto next paged link it gives white page.
I have reset Permalink Settings because thats the only solution i found on the Internet. Still nothing same problem.
In the database their are total of 9 records under this custom post type so by pagination it will be 3 per page.
Pagination Code
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
'post_type' => 'schedules',
'posts_per_page' => 3,
'post_status' => 'publish',
'paged' => $paged
);
query_posts($args);
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$schedules_vessel = get_field('schedules_vessel');
$schedules_voyage = get_field('schedules_voyage');
$schedules_port = get_field('schedules_port');
$schedules_country = get_field('schedules_country');
$schedules_arrival = get_field('schedules_arrival');
$schedules_departure = get_field('schedules_departure');
$date = DateTime::createFromFormat('d/m/Y h:i A', $schedules_arrival);
$schedules_arrival_date = $date->format('d M Y');
$schedules_arrival_time = $date->format('G:i');
$date = DateTime::createFromFormat('d/m/Y h:i A', $schedules_departure);
$schedules_departure_date = $date->format('d M Y');
$schedules_departure_time = $date->format('G:i');
?>
<?php endwhile; endif; ?>
<?php require_once( get_template_directory() . "/snippets/pagination.php"); ?>
In pagination.php
<?php
global $wp_query;
$temp = "";
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_text' => 'Previous',
'next_text' => 'Next',
'type' => 'list'
));
?>
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow