Opened 16 months ago

Last modified 3 weeks ago

#19866 new enhancement

Allow specifications of any wp_posts field(s) in WP_Query

Reported by: bigdawggi Owned by:
Priority: normal Milestone: Awaiting Review
Component: Query Version:
Severity: normal Keywords:
Cc: xoodrew@…, mike@…

Description

Hi guys, I'm considering writing a patch to be able to pull specific fields from a WP_Query but wanted to see if there was already something in the works on another ticket. I searched trac and hackers list (via its Google Group) and surprisingly didn't see anything.

Here's the current implementation which limits people to only querying for certain fields: wp-includes/query.php:2033

		switch ( $q['fields'] ) {
			case 'ids':
				$fields = "$wpdb->posts.ID";
				break;
			case 'id=>parent':
				$fields = "$wpdb->posts.ID, $wpdb->posts.post_parent";
				break;
			default:
				$fields = "$wpdb->posts.*";
		}

Stems from a situation where we needed all posts of a certain type -- potentially thousands -- but really only required post_title and ID fields, so didn't want all that memory overhead.

Change History (3)

  • Cc xoodrew@… added

Replying to bigdawggi:

Stems from a situation where we needed all posts of a certain type -- potentially thousands -- but really only required post_title and ID fields, so didn't want all that memory overhead.

If there's a performance improvement to be had by being able to specialize queries, this would come in really handy. +1

  • Cc mike@… added
Note: See TracTickets for help on using tickets.