Reputation: 61
I am pulling an RSS feed from a Wordpress site, and it seems to have got stuck retrieving a cached version through the PHP on my site.
Viewing the RSS url via a browser shows ALL of the 8 or so posts that should be showing but DOESN'T show a post that I deleted as a test.
Outputting the raw data from the feed via the PHP (using LastRSS) it's omitting posts that were created yesterday but is still showing the deleted post.
LastRSS gets the feed using fopen():
if ($f = @fopen($rss_url, 'r')) {
$rss_content = '';
while (!feof($f)) {
$rss_content .= fgets($f, 4096);
}
fclose($f);
}
I've not used Worpress or RSS feeds all that much, so any help would be appreciated.
Upvotes: 4
Views: 7361
Reputation: 13135
It seems that the current way to do this in 2020 is with this code:
function turn_off_feed_caching( $feed ) {
$feed->enable_cache( false );
}
add_action( 'wp_feed_options', 'turn_off_feed_caching' );
However, for me, the thing that actually flushed the cache was simply making a change to one of the articles in the feed.
I was trying to switch between Full Text and Summary modes in the plugin and spent several hours trying things until I just tried editing a post and it worked straight away then.
Upvotes: 3
Reputation: 2101
@bodi0 has the right answer but the code has now been depreciated. The following code uses an anonymous function to achieve the same result:
add_filter('wp_feed_cache_transient_lifetime', function () {
return 0;
});
Upvotes: 1
Reputation: 31919
WordPress’ built-in RSS
widget is fantastic, but sometimes it doesn’t update often enough.
Luckily, there is a fairly simple solution for that. Just add this code to your functions.php
file:
add_filter( 'wp_feed_cache_transient_lifetime',
create_function('$a', 'return 600;') );
As you can see, we are using WordPress’ add_filter()
function, which accepts a filter hook, callback function and (optional) priority. The wp_feed_cache_transient_lifetime
hook handles the feed’s refresh rates. We’re creating our callback function on the fly using PHP’s create_function()
function. It is one line, which returns the refresh rate in seconds. Our refresh rate is set to 10 minutes (600 seconds).
Set the value in seconds according your needs.
Upvotes: 2