Skip to content

Latest commit

 

History

History
12 lines (7 loc) · 852 Bytes

wp-query-tips.md

File metadata and controls

12 lines (7 loc) · 852 Bytes

WP_Query tips

A series of performance tips to keep in mind when you're using WP_Query

"posts_per_page" => -1

WP_Query, and its sibling functions get_posts() and query_posts(), is useful in that it allows you to grab an unlimited set of results with "posts_per_page" => -1. This feature isn't without its downside, however. Another feature of WP_Query is that it will pre-fetch all of the post data associated with your query — post meta, taxonomy terms, etc.

When "posts_per_page" => -1 (or greater than 500), WP_Query won't pre-fetch post data, and instead run a number of queries to fetch the full representation of each post.

If you need a lot of posts, you should instead set a high upper bound like "100".