0

I have seen that the filter wp_feed_cache_transient_lifetime can be used to set the cache period for fetch_feed. But this seems to set it globally for all feeds. Is there a way to have a different cache period per feed?

This is useful in my case where I have multiple feeds for quite different purposes. some feeds are clearly being refreshed very quickly, while I don't expect others to be updated more than once per month.

The issue with these RSS feeds is if they are not cached properly they slow down the page noticeably.

1 Answer 1

1

You can use the second parameter passed to the wp_feed_cache_transient_lifetime filter which, in the context of fetch_feed(), is the URL of the feed:

add_filter( 'wp_feed_cache_transient_lifetime', function ( $time, $url ) {
    if ( $url === 'https://example.com/rss' )  {
        $time = MONTH_IN_SECONDS;
    }

    return $time;
}, 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.