WordPress should not unnecessarily query posts at page load
|Reported by:||junsuijin||Owned by:||junsuijin|
|Cc:||Denis-de-Bernardy, steve@…, westi, matt@…, mtdewvirus@…|
For plugins like BuddyPress, with pages that have no WordPress post content, a query for posts at load time creates unnecessary overhead. I've tested this patch (with WordPress MU) and it removes 3 queries on all pages when the 'NO_QUERY' constant is defined. A very quick scan of page load times also suggests about 20% in time savings on average.
Other plugins like shopping carts and any others that needn't query the WordPress posts table can benefit from this as well.
My previous means of achieving this effect was to simply return null to the 'posts_request' filter, which removes only 2 queries per page.
The devised method uses suggestions from azaozz and sivel, and allows for setting the definition of 'NO_QUERY' using the 'init' action hook. It also still allows for further querying of the posts at a later point if necessary.
I welcome further suggestions about the patch, and any other ways this could be accomplished more effectively.