0

it seems that there are only 10 posts being displayed on author.php file. The theme I'm using have just this in author.php file:-

<?php while ( have_posts() ) : the_post(); ?>

<?php endwhile; ?>
<?php wt_pagination(); ?>

The loop is getting only first 10 posts (of the author). How can I change it to first 30 posts. Without writing a secondary (custom) loop.

1 Answer 1

1

when you use the loop the number of post displayed is choosen fron the option set in Settings->Reading in you backend. It affects all the standard loops, not only the author page.

To change only for author page you have to use pre_get_posts hook and set the wanted number of posts using posts_per_page argument:

add_action('pre_get_posts','change_numberposts_for_author');

function change_numberposts_for_author( $query ) {
  if ( ! is_admin() && $query->is_main_query() && is_author() ) {
    $query->set('posts_per_page', 30); // 30 is the number of posts
  }
}

See also is_author() on Codex

13
  • 3
    Well, you wrote exactly the same thing at exactly the same time. So, I'll defer to your answer. :) Oct 8, 2013 at 17:41
  • 1
    Damn you are just quicker :D the same answer twice really isn't necessary.. Oct 8, 2013 at 17:46
  • 1
    Shouldn't this work? $query->is_main_query() && $query->is_author() Or am I missing something? And one could additionally add this if ( is_admin() || ! $query->is_main_query() ) return; at the beginning of the function. Oct 8, 2013 at 18:35
  • 1
    Fixed $query->is_main_query() in the answer. Oct 8, 2013 at 18:57
  • 1
    Isn't the addition of $query-> just what I suggested, but whatever.. :D Oct 8, 2013 at 19:36

Your Answer

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

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