使用 Simplepie fetch_feed() 管理 RSS 缓存

发布于 2024-09-26 23:45:01 字数 546 浏览 0 评论 0原文

rss 文件更新后如何强制刷新?无论如何,它似乎都在缓存...

该提要使用 simplepie fetch_feed() 方法位于 WordPress 仪表板小部件中...

/* Dashboard Widget */
function my_dashboard_widget_function() { 
    $rss = fetch_feed( "http://mysite.com/feed.rss" );

     if ( is_wp_error($rss) ) {
          if ( is_admin() || current_user_can('manage_options') ) {
               echo '<p>';
               printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
               echo '</p>';
          }
     return;
}

How can I force a refresh when the rss file has been updated? It appears to be caching no matter what...

The feed is located in a WordPress dashboard widget using the simplepie fetch_feed() method...

/* Dashboard Widget */
function my_dashboard_widget_function() { 
    $rss = fetch_feed( "http://mysite.com/feed.rss" );

     if ( is_wp_error($rss) ) {
          if ( is_admin() || current_user_can('manage_options') ) {
               echo '<p>';
               printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
               echo '</p>';
          }
     return;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2024-10-03 23:45:01

add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return 3600;' ) );

//其中3600是缓存持续时间(以秒为单位)。

add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return 3600;' ) );

//Where 3600 is the cache duration in seconds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文