WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can´t get works fine the pagination in archives for wordpress when i want limite the posts by page , if i let pagination by default as 10 from backend i haven´t problems but if i use this no works

$wp_query->posts_per_page = 5;
if ( have_posts() ) : while ( have_posts() ) : the_post();

For example in other pages i can limit the posts by page without problems but in archive always have problems for paginate , or give errors 404 in some pages or paginate bad , etc


share|improve this question

You should not be setting the posts_per_page value in the template, nor should you be setting the object property directly after the query has run. That is going to cause the object data to become out of sync with itself.

You need to alter that value with a filter on pre_get_posts.

function pregp_archive_ppp_wpse_108225($qry) {
  if ($qry->is_main_query() && $qry->is_archive()) {

The precise conditions you need may be different from the above example. You may need, for example, is_page_template() instead of is_archive().

share|improve this answer
And with my example how i can fix for works because i want use this in the archive template page – Fran Jul 29 '13 at 15:57
Did I not just answer that question? – s_ha_dum Jul 29 '13 at 16:16

Your Answer


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.