Ive created an author.php to show the author's posts, with pagination. When clicked the next button, takes me to page two but not using the same template. Any reason?
My query in author.php
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'author' => $curauth->ID,
'orderby' => 'post_date',
'order' => 'DSC',
'paged' => $paged,
'post_type' => 'post',
'posts_per_page' => 1, // there are more
);
$authors_posts = new WP_Query( $args );
Links:
<?php echo get_next_posts_link( 'Next', $authors_posts->max_num_pages ); ?>
<?php echo get_previous_posts_link( 'Previous' ); ?>
WP_Query
. – Sylar Jul 31 '17 at 12:01pre_get_posts
if you wish to alter the main query parameters. – Milo Jul 31 '17 at 12:04pre_get_posts
, you're correct it does useWP_Query
, but why throw away the first query? It's wasteful, just modify it instead via the filter – Tom J Nowell♦ Jul 31 '17 at 12:16