Custom wordpress feed issue (for ics feed)

For users of amr-events:

If you are:

  • using or offering your users the ics feed (to subscribe to whole calendar) and
  • you have more than 10 (or more accurately, more than your posts_per_rss feed parameter setting) active recent events, then please either
    1. In your wordpress settings> reading increase the “Syndication feeds show the most recent” (aka “post_per_rss”) setting to a number larger enough to cover all the events that you wish to include in the calendar subscription feed ( temporarily until the next larger upgrade – there should be one with additional features before Christmas).  This will also update the number of posts that show in your rss feed.       or
    2. upgrade to amr-events v 1.1.1 or
    3. manually apply the small code change below.

Code Change:

1. In file wp-edit-event.php, right near the bottom around line 604, find function ical_adjust_query. At the top of this function,before the other code  add:

//  if the query is doing the ics feed, then we need to make doubly sure that it will get all feeds, since wp overwrites the post_per_page parameter.

 if (isset ($query->query_vars['feed']) and ($query->query_vars['feed'] == 'ics'))
     add_filter('post_limits','amr_no_limits_for_feed'); // this filter will clear the  limits

2. Then above  function ical_adjust_query, add a new function:

function amr_no_limits_for_feed($limits) { //wordpress overwrites our 'unlimited posts_per_page' parameter if the query is n a feed and imposes the rss feed limit.  This will remove the limit. Only call if it is a ics feed
 return ('') ;


A user of amr-events (Shourin Sen , using the plugin for ip, entertainment and art law events) brought to my attention that the ics feed was not showing all events – it was behaving like an rss feed – only showing the last x events.

This was very puzzling since the ics feed code uses the same functions to get the event posts as the shortcodes and the widgets and they got all the data they needed.   It seemed like the “posts_per_page=-1” argument passed was being ignored when in the feed.

post_per_page = -1 is supposed to fetch all posts.

I dug down into the wordpress code and at line 1687  in wp-includes/query.php found that if the query was in a feed, then wordpress fetched the “posts_per_rss” option and overwrote (without checking) whatever value was in post_per_page.

Is this a wordpress bug?

Maybe? – there may be a case for ignoring the parameter in case plugin or theme developers forget that changes they make to the query may impact the feed to,  although all the other examples do suggest checking whether in a feed or not before applying changes to the query, so arguably the wp code should not just overwrite it.

Certainly the codex needs to highlight this to help developers.  Therefore I have updated the wordpress documentation  in a couple of places, but I have not logged it as a bug in the wp trac.