[wp-trac] [WordPress Trac] #19866: Allow specifications of any wp_posts field(s) in WP_Query
WordPress Trac
noreply at wordpress.org
Sat Jan 10 14:42:09 UTC 2015
#19866: Allow specifications of any wp_posts field(s) in WP_Query
-------------------------+-----------------------
Reporter: bigdawggi | Owner:
Type: enhancement | Status: reopened
Priority: normal | Milestone:
Component: Query | Version:
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-------------------------+-----------------------
Comment (by boonebgorges):
A slightly better approach here is to do something like the following
(assuming split_the_query): Do the `SELECT ID` query as per usual. Then,
once we have an array of matched post IDs, fill the `posts` objects only
with the fields requested in the 'fields' array. And for each of those, we
would first check the cache, to avoid doing an additional query if
possible. So, fetching ID+post_title would result in two queries: `SELECT
ID WHERE...` and `SELECT post_title WHERE IN ($ids)`.
This is slightly better because it doesn't ignore the cache when
populating the post objects. But it's still not great because (a) it
doesn't *update* the cache, so subsequent versions of the same query will
still require hitting the DB (though perhaps we could avoid this by always
querying for the full object if a persistent cache is found?), and (b) as
nacin notes, trying to use `$query->posts` objects alongside any other WP
APIs (like template loops) is going to result in database hits to populate
the full post object.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/19866#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list