Title: Fetch_Feed cache time
Last modified: August 21, 2016

---

# Fetch_Feed cache time

 *  [Dave Navarro, Jr.](https://wordpress.org/support/users/dnavarrojr/)
 * (@dnavarrojr)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/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](https://wordpress.org/support/users/c3mdigital/)
 * (@c3mdigital)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/fetch_feed-cache-time/#post-3986228)
 * 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.

## Tags

 * [cache](https://wordpress.org/support/topic-tag/cache/)
 * [fetch_feed](https://wordpress.org/support/topic-tag/fetch_feed/)
 * [RSS](https://wordpress.org/support/topic-tag/rss/)

 * In: [Requests and Feedback](https://wordpress.org/support/forum/requests-and-feedback/)
 * 1 reply
 * 2 participants
 * Last reply from: [Chris Olbekson](https://wordpress.org/support/users/c3mdigital/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/fetch_feed-cache-time/#post-3986228)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
