【WordPress相关】提速 WP_Query 和 query_posts 函数的小技巧
作品分类:Wordpress相关 查询 这类 函数 提速 小技巧 函数 query_posts WP_Query
提速 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_Query
和 query_posts
其实提供了 no_found_rows
参数可以阻止进行这类的 SQL 查询,比如:
query_posts('no_found_rows=true&cat=1&numberposts=1');
另外说一下:get_posts
函数自动设置了这个参数为 true
本站推荐使用的主机:,国外主机建议使用。
原创文章,作者:starterknow,如若转载,请注明出处:https://www.starterknow.com/32323.html