2

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:

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?

3

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.