本网站使用的Memcached缓存,但是近期发现一个问题,因为有部分内容需要回复评论才能显示。但是当评论后并没有刷新评论不显示。
网站使用Memcached缓存的方法——WordPress安装memcached提升网站速度

解决办法
将以下代码添加到主题的functions.php文件中即可
- // 禁用评论Memcached缓存
- function disable_comment_memcached_cache($comment_args) {
- if (is_singular() && comments_open()) {
- $comment_args['update_comment_cache'] = false;
- $comment_args['cache'] = false;
- }
- return $comment_args;
- }
- add_filter('comments_template_query_args', 'disable_comment_memcached_cache', 999);
- // 强制评论查询不走缓存
- function disable_comment_query_cache($query) {
- if (is_singular() && comments_open()) {
- $query->query_vars['cache'] = false;
- }
- }
- add_action('pre_get_comments', 'disable_comment_query_cache', 999);
添加后再前端测试即可显示最新评论~




2026年5月15日 下午2:25 沙发
你这代码是直接把缓存关了吧
2026年5月15日 下午2:30 1层
@秋风于渭水 当前文章关闭评论缓存
2026年6月1日 下午2:31 2层
@ts小陈 提示已登陆用户评论不能带链接,评论不了。
2026年6月1日 下午2:32 3层
@蒙需 是的 禁止评论中带链接
2026年5月15日 上午10:42 板凳
终于找到这篇文章了,感谢小陈的分享!
2026年5月15日 上午10:32 地板
测试缓存~
2026年5月15日 上午10:29 4楼
学习到了,感谢小陈
2026年5月15日 上午10:03 5楼
谢谢分享,希望小陈长长久久