Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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');
share|improve this answer
    
Works great thank you! –  dragonfeet2012 Feb 6 '13 at 16:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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