百度 | 神马 | 搜狗 | 技术文档 | 学习资料分享 - 记录帝国CMS及运维技术的点点滴滴
你的位置:首页 > 实用IT技术 » 正文

【Wordpress相关】提速 WP_Query 和 query_posts 函数的小技巧

发布时间:2020-09-17

提速 WP_Query 和 query_posts 函数的小技巧,

我们在使用 WP_Query 或者 query_posts 进行日志查询的时候,WordPress 都会产生很多 SQL_CALC_FOUND_ROWS 的 SQL 查询。

一般来说这类 SQL 查询,数据库是不会进行缓存,我前面也说了 ,因为慢。

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>

WP_Queryquery_posts 其实提供了 no_found_rows 参数可以阻止进行这类的 SQL 查询,比如:

query_posts('no_found_rows=true&cat=1&numberposts=1');

另外说一下:get_posts 函数自动设置了这个参数为 true


本站推荐使用的主机:,国外主机建议使用

Top