我使用以下代码创建了自定义RSS提要:
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.
}
这很好,但我似乎无法禁用缓存——我正在开发提要,需要在进行更改时看到它刷新。
我尝试了以下方法:
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\' );
对于自定义提要,禁用提要缓存的操作是否有所不同?
SO网友:EliT
我知道这个问题已经有一年多了,你可能已经找到了解决办法。如果这对某人有帮助,我想出了一个解决方案,在init挂钩上添加一个提要,当插件停用时将其删除,并在插件重新激活时将其添加回来。提要删除代码基于add_feed 函数在WordPress中执行,只需将其撤消即可。
/*
* 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\' );