michel lompret michel lompret - 13 days ago 5
Ajax Question

Ajax load more and query in wordpress

I try to have a load more button for my posts. It works great except the third time when get the same three posts for example if I had posts t10 to t1 . I get t10 t9 t8 then when I click on load more I get t7 t6 t5 and the third time I get the same 3 posts and after that i always get these 3 posts. I think the problem come from offset but it seems ok to me

Answer

You can use paged parameter instead of offset, page is mean for static front page.

paged (int) - number of page. Show the posts that would normally show up just on page X when using the "Older Entries" link.

posts_per_page (int) - number of post to show per page (available since Version 2.1, replaced showposts parameter). Use 'posts_per_page'=>-1 to show all posts (the 'offset' parameter is ignored with a -1 value). Set the 'paged' parameter if pagination is off after using this parameter.

Codex : Pagination parameters

Hope it helps!