A search on this topic on this site throws up a lot of results claiming to have resolved this issue, but I am having a contrary experience after implementing these guidelines as outlined here:
- How to fix pagination for custom loops?
- Pagination not working on static page
- https://stackoverflow.com/questions/14026467/pagination-on-static-front-page-wordpress
This is my code below:
// Get current page and append to custom query parameters array
$custom_query_args['paged'] = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
// Define custom query parameters
$custom_query_args = array(
'post_type' => 'post',
'posts_per_page' => '4',
'paged' => $custom_query_args['paged'],
'post_status' => 'published',
'cat' => '1',
);
// Instantiate custom query
$blog_query = new WP_Query( $custom_query_args );
// Pagination fix
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $blog_query;
?>
<?php if ( $blog_query->have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( $blog_query->have_posts() ) : $blog_query->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php endif; // end have_posts() check ?>
<?php // Reset postdata
wp_reset_postdata();
// Custom query loop pagination
previous_posts_link( 'Older Posts' );
next_posts_link( 'Newer Posts', $blog_query->max_num_pages );
// Reset main query object
$wp_query = NULL;
$wp_query = $temp_query;
?>
When I click on the pagination link displayed on the frontpage, a 404 Not Found response is shown. (The requested URL /kobopulse/page/2/ was not found on this server.)
I am using the latest version of wordpress. On the settings page my install is configured to display a static front page. Front-page.php is my custom page template for the frontpage
What do I need to do differently.
Thanks