I am building a mobile application that is pulling the json feed from a blog. I can easily query to get the latest 10 posts for example. But next, I want to be able to query the next 10. This presents me with a problem, because while pulling the first 10, another 2 posts may be added, so if I try to pull the next ten posts, I would get duplicates and get 8 unique posts instead of 10. I am trying to think of a way that I can simply get my last post id retireved, and request for the next ten posts after post id = x. I guess technically I would be getting the next 10 posts "before" that id, but I hope I explained my question.


I download recent posts

30 29 28 27 26 25 24 23 22 21

now I want to download next 10

20 19 18 17 16 15 14 13 12 11

Works perfect. But what happens if I want to download the next ten while x new posts were added. In this case we'll use 3 as x

Download first 10

30 29 28 27 26 25 24 23 22 21

now the next 10 Whoops. Someone added 3 new posts still try to get next 10

23 22 21 20 19 18 17 16 15 14

Got duplicates of 23 22 21.

I want to say get last post download aka(21) and take next ten after that

How would I make the api in the address bar to handle this?

  • How the "another 2 posts may be added" works ? I mean how you are getting these 2 posts, please add your code if possible. – Shazzad Jan 18 '14 at 8:29
  • Let's say I do api/get_posts/?count=10. This gives me the last 10 posts. Now I would like to get 11-20. Before I get 11-20, 2 new posts are added (theoretically). Now I can't just get 11-20 I need to get 13-22 – EGHDK Jan 18 '14 at 8:58
  • Ok, so the two post that added theoretically is on the same order as the first 10 were ? You can use offset on the API script which will calculate position rather using page. So query - api/get_posts/?count=10&offset=12 would get posts – Shazzad Jan 18 '14 at 9:03
  • Updated my question. – EGHDK Jan 18 '14 at 9:19

Ha... While this makes a lot of sense, WP is not to good with arbitrary conditions like this and nothing like is implemented in WP_Query currently.

However since your issue is really chronological rather than requiring dealing with IDs, you probably can make use of Date Parameters to restrict results to be older than time of oldest post you fetched instead of explicit offset by count.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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