Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop Wordpress from returning a cached RSS feed?

Tags:

php

rss

wordpress

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.

like image 597
Jaykizi Avatar asked Oct 23 '25 19:10

Jaykizi


1 Answers

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.

like image 131
rtpHarry Avatar answered Oct 26 '25 09:10

rtpHarry