Support » Requests and Feedback » Fetch_Feed cache time

  • Please update Fetch_Feed to support an optional parameter for the cache time value.

    I know that I can change the global time using the wp_feed_cache_transient_lifetime filter, but I need the ability to set individual cache times. Some feeds I want to update more quickly than others.

    In my testing, I modified fetch_feed with the following:

    function fetch_feed( $url, $cache_time = NULL )
    	if ($cache_time == NULL) {
    	  $cache_time = apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url );
    	$feed->set_cache_duration( $cache_time );

    which doesn’t break existing calls, but allows me to set individual cache times for feeds.

Viewing 1 replies (of 1 total)
  • Chris Olbekson


    Level 12 Bug Squasher & Forum Moderator

    You can always remove the filter directly after the call to fetch_feed(). Probably better than hacking core is to create a wrapper function that allows you set the cache time individually for each feed.

    function dn_fetch_feed( $url, $cache_time = false ) {
         if ( $cache_time ) {
             add_filter( 'wp_feed_cache_transient_lifetime', function() {
                 return $cache_time;
             $feed = fetch_feed( $url );
             remove_all_filters( 'wp_feed_cache_transient_lifetime' );
            return $feed;
        return fetch_feed( $url );
Viewing 1 replies (of 1 total)
  • The topic ‘Fetch_Feed cache time’ is closed to new replies.