Pagination 404 errors for author posts query on author.php

I’m trying to query all posts by an author and paginate them on the author.php page. I’ve tried messing with the WP default blogs per page settings and that doesn’t help. I’ve looked at other posts on here and could find a solution either. This works on my category pages and custom template pages (with the exception of the author attribute).

Here’s what I have for my query:

Read More
if (get_the_author_meta( 'ID' )) {
  $authorID = get_the_author_meta( 'ID' );
}
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array(
    'post_type' => 'post',
    'author'=>$authorID, 
    'orderby'=> 'date',
    'showposts'=>'5',
    'paged'=>$paged
);
$query = new WP_Query( $args );

I even tried query_posts() with no luck.

The query itself works, but the pagination breaks. Any ideas?

Related posts

Leave a Reply

1 comment

  1. There is already a query on that page. author.php is an optional template file that, if present, WordPress will use for author archives. You shouldn’t have to create another query on that page. I think that your query and the native query are colliding, at least in part because both queries will be using the same paged query var.

    If you need to change something about the query, you should probably be interrupting the main query for that page instead of creating a new query.

    function alter_author_wpse_84696() {
      if (!is_author()) return false;
      global $wp_query;
      $wp_query->set('posts_per_page', 10);
      $wp_query->set('order', 'ASC');
    }
    add_action('pre_get_posts','alter_author_wpse_84696');