I'm using a custom query to get all CPT posts for the author in author.php
. I have a lot of authors and a lot of content so I'm using the wp pagenavi plugin to paginate between these posts.
For some reason the pagination is giving me 404 errors on a lot of these pages. The pages that throw 404s is always the last or the two last pages of the pagination.
So for example /author/steve/page/8/
will work, while /author/steve/page/9/
and /author/steve/page/10/
will not.
I believe the pagenavi plugin handles 'paged' => $paged
, but i've also tried setting $paged in the file: $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
, but with no difference.
My global post_per_page (in the dashboard setting) is 6 posts per page.
Changing 'posts_per_page' => 4
in the query to 'posts_per_page' => 6
, fixes the 404 issue, but is more of a dirty fix as I need to only display 4 posts per page.
Below is my query:
<?php
$author_id = get_the_author_meta( 'ID' );
if ( have_posts() ) :
the_post();
rewind_posts();
$author_details = $wp_query->get_queried_object();
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query(array(
'post_type'=> 'publikasjoner',
'paged' => $paged,
'posts_per_page' => 4,
'meta_key' => 'rapportnummer',
'orderby' => 'meta_value_num',
'order' => 'DSC',
'author_name' => $curauth->user_nicename
));
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
// Post content
<?php endwhile; endif;
if(function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' => $wp_query ) ); }
$wp_query = null; $wp_query = $temp; ?>