Why is the filter removed after fetching feeds in the following example (from WordPress.org?)

function return_7200( $seconds )
  // change the default feed cache recreation period to 2 hours
  return 7200;

add_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' );
$feed = fetch_feed( $feed_url );
remove_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' );

The filter is added before the call to fetch_feed, then immediately removed so only that particular feed is given a different feed cache transient lifetime. Any other fetch_feed calls within the lifetime of the request won't have that filter applied, so will be given whatever the default cache transient lifetime value is.

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.