Disable feed cache for custom RSS feed?

I created my custom RSS feed using the following code:

add_action( 'init', 'MyCustomRSS' );
function MyCustomRSS(){
   add_feed( 'examplecomrss', 'MyCustomFeedCallback' );
}

/* This code seeks the template for your RSS feed */
function MyCustomFeedCallback(){
    get_template_part( 'rss', 'examplecomrss' ); // need to be in small case.
}

This works well, but I can't seem to disable the cache -- I'm developing the feed and need to see it refreshed when I make changes.

I've tried the following:

add_filter('wp_feed_cache_transient_lifetime', function() {
    return 10;
});

// disable feed cache
function turn_off_feed_caching( $feed ) {
    // I tried the following line also with no luck
    // $feed = fetch_feed( bloginfo_rss('url') );
    $feed-enable_cache( false );
}
add_action( 'wp_feed_options', 'turn_off_feed_caching' );

Is the action to disable feed caching somehow different for custom feeds?

Topic rss cache Wordpress

Category Web


I know the question is over a year old, and you probably already found a solution. In case this helps someone, here is a solution I came up with that adds a feed on an init hook, removes it when the plugin is deactivated, and also adds it back when the plugin is re-activated. The feed removal code is based on what the add_feed function does in WordPress, and just undoing that.

/*
 * Function that loads my PHP module that outputs the RSS feed
 */                                                                                                                                                                                                                                       
function my_podcast_rss()
{
    require_once plugin_dir_path( __FILE__ ) . 'templates/archive-custom_post_type_name.php';
}

/*
 * Add the feed
 */
function add_my_rss_feed()
{
    add_feed('my-feed-name', 'my_podcast_rss') );
    delete_option( 'rewrite_rules' );
}

/*
 * Call during the 'init' hook
 * Also call during activation (otherwise, when deactivating and
 * reactivating, my changes weren't applying somehow).
 */
add_action( 'init', 'add_my_rss_feed')
register_activation_hook( __FILE__, 'add_my_rss_feed' );

/*
 * Remove the feed
 * Call during deactivation
 */
function deactivate_my_plugin_name()
{   
    $hook = 'do_feed_' . 'my-feed-name'
    remove_action($hook, 'my_podcast_rss'), 10, 1);
    delete_option( 'rewrite_rules' );
}   
register_deactivation_hook( __FILE__, 'deactivate_my_plugin_name' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.