I'm having trouble setting up an author archive. I've come up with a few different loops, but I can't seem to get them quite right. I just want it to list all posts by the current author.

This shows posts by the current author, but only 10 posts (my default number, I guess):

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    <?php endif; ?>

This one lists all post by all authors.

<?php global $post;
    $args = array('numberposts' => -1);
    $custom_posts = get_posts($args);
    foreach($custom_posts as $post) : setup_postdata($post); ?>
        <li <?php post_class($custom_classes) ?> id="post-<?php the_ID(); ?>" role="article"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endforeach;?>

This doesn't seem that hard. I'm probably missing something obvious. It seems like I need to get the author into a variable and pass it, but I thought that was assumed on the author archive. My attempts to do that just haven't worked.

1 Answer 1


your get_posts overrides the normal query_posts query. For this to work properly you should use query_posts and merge in your numberposts setting with the original query, like so:

global $wp_query;
$args = array_merge( $wp_query->query, array( 'numberposts' => -1 ) );
query_posts( $args );

Then you'll no longer need a custom loop either, you could just use a normal loop.

  • According to the docs, 'numberposts' and 'posts_per_page' can be used interchangeably. In practice however, for me, numberposts didn't work while posts_per_page did. Commented May 15, 2017 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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