Support » Fixing WordPress » Loop: pagination doesn't work

  • Resolved MultiformeIngegno


    What’s wrong with this code?

    Why if I click on “Next page” I go to /page/2/ but the same posts of page 1 are displayed? If I click on “next page” on /page/2/ I go to /page/3/ but still the same posts are shown (and so on)..

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    This is your problem.

    query_posts( 'cat=1&posts_per_page=2' );

    More info:

    Thanks, marked as solved.
    Out of curiosity, why on category.php pagination works without having the paged param?

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Because you’re not doing a query_posts there?

    The query_posts() function changes the main query for the page. When you use it, you override the “automatic” main query which takes everything into account normally, and tell it that you want to do something other than the default.

    Really, you should use the pre_get_posts filter instead of the query_posts() function. Then you can modify the main query instead of overriding it entirely.

    Thanks, I’ll read about pre_get_posts. Never heard of it before, always used query_posts. Will have a look! 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Loop: pagination doesn't work’ is closed to new replies.