【问题标题】:WordPress | Transient the default WP_Query resultsWordPress |瞬态默认 WP_Query 结果
【发布时间】:2013-07-17 15:31:48
【问题描述】:

我创建了一个流量很大的网站,并且我使用了 WordPress 瞬态来“缓存”请求的数据。直到这里,我的自定义查询和 WP_Query 的使用都很好。

我的问题是,如何在类别中“缓存”WordPress“循环”返回的数据?

在类别主题文件中,我使用默认循环代码来打印数据,但我无权访问该主题文件的 WP_Query 结果。

那么,有没有办法将 WordPress 提供的数据缓存在类别中?

【问题讨论】:

    标签: wordpress caching transient


    【解决方案1】:

    Wordpress documentation 的建议是安装 Persistent 缓存插件

    【讨论】:

    • 我知道,但这不是我这次需要的。我只需要按原样缓存数据。
    • 好的,我发布的链接应该仍然有帮助:codex.wordpress.org/Class_Reference/WP_Object_Cache$result = wp_cache_get( 'my_result' ); if ( false === $result ) { $result = $wpdb->get_results( $query ); wp_cache_set( 'my_result', $result ); } // Do something with $result;
    猜你喜欢
    • 2020-05-02
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 2017-04-12
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多