I am basically creating an iphone app that get’s it’s data from wordpress. WordPress will serve audio and video links via a RSS feed to the iphone app. I have the feed and audio player working great but can’t seem to find anything related to how to create a custom feed where I can specify pagination like start=0&items=10. A plugin would be great but I can code something up in PHP if anyone has any ideas.
I am basically creating an iphone app that get’s it’s data from wordpress. WordPress
Share
I’m going to answer this question by changing the standard RSS feed of a WordPress installation to respond to limits passed by query parameters. As you say you’ve already got a working feed, this should hopefully give you everything else you need.
By default, the standard feeds in WordPress are limited by the setting “Syndication feeds show the most recent X items” on the Settings→Reading page, and are unpaginated, as that wouldn’t generally make sense for an RSS feed. This is controlled by WordPress’s WP_Query::get_posts() method, in
query.php, if you’re interested in taking a look at how things work internally.However, although the feed query’s limit is set to
LIMIT 0, X(where X is the above setting, 10 by default) , you can override the limit by filtering the query in the right place.For example, the filter
post_limitswill filter the LIMIT clause of the query between the point it’s set up by the default code for feeds and the time it’s run. So, the following code in a plugin — or even in your theme’s functions.php — will completely unlimit the items returned in your RSS feeds:(At this point I should mention the obvious security implications — if you’ve got 20,000 posts on your blog, you’ll cause yourself a lot of server load and bandwidth if if lots of people start grabbing your feed, and you send out all 20,000 items to everyone. Therefore, bear in mind that whatever you end up doing, you may still want to enforce some hard limits, in case someone figures out your feed endpoint can be asked for everything, say by analysing traffic from your iPhone app.)
Now all we’ve got to do is to respond to query parameters. First of all, we register your two query parameters with WordPress:
That allows us to pass in the
startanditemsvariables you’re suggesting for your URL parameters.All we have to do then is to adjust our original
LIMITchanging function to respond to them:And there you go. Throw those last two blocks of code at WordPress, and you can now use a URL like this on any of your existing feeds:
For this example, you’ll get the normal RSS feed, but with 25 items starting from item number 30.
…and if you don’t pass the query parameters, everything will work like normal.