mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-09 07:00:01 +00:00
Introduce 'fields' query var to WP_Query. See #14777
git-svn-id: http://svn.automattic.com/wordpress/trunk@15982 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5a81941fed
commit
57a7c073ef
@ -1179,10 +1179,11 @@ class WP_Query extends WP_Object_Query {
|
|||||||
, 'preview'
|
, 'preview'
|
||||||
, 's'
|
, 's'
|
||||||
, 'sentence'
|
, 'sentence'
|
||||||
|
, 'fields'
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $keys as $key ) {
|
foreach ( $keys as $key ) {
|
||||||
if ( !isset($array[$key]))
|
if ( !isset($array[$key]) )
|
||||||
$array[$key] = '';
|
$array[$key] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1190,7 +1191,7 @@ class WP_Query extends WP_Object_Query {
|
|||||||
'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and');
|
'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and');
|
||||||
|
|
||||||
foreach ( $array_keys as $key ) {
|
foreach ( $array_keys as $key ) {
|
||||||
if ( !isset($array[$key]))
|
if ( !isset($array[$key]) )
|
||||||
$array[$key] = array();
|
$array[$key] = array();
|
||||||
}
|
}
|
||||||
return $array;
|
return $array;
|
||||||
@ -1640,7 +1641,7 @@ class WP_Query extends WP_Object_Query {
|
|||||||
$join = '';
|
$join = '';
|
||||||
$search = '';
|
$search = '';
|
||||||
$groupby = '';
|
$groupby = '';
|
||||||
$fields = "$wpdb->posts.*";
|
$fields = '';
|
||||||
$post_status_join = false;
|
$post_status_join = false;
|
||||||
$page = 1;
|
$page = 1;
|
||||||
|
|
||||||
@ -1721,6 +1722,17 @@ class WP_Query extends WP_Object_Query {
|
|||||||
else
|
else
|
||||||
$q['no_found_rows'] = false;
|
$q['no_found_rows'] = false;
|
||||||
|
|
||||||
|
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.*";
|
||||||
|
}
|
||||||
|
|
||||||
// If a month is specified in the querystring, load that month
|
// If a month is specified in the querystring, load that month
|
||||||
if ( $q['m'] ) {
|
if ( $q['m'] ) {
|
||||||
$q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
|
$q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
|
||||||
@ -2257,6 +2269,7 @@ class WP_Query extends WP_Object_Query {
|
|||||||
$groupby = 'GROUP BY ' . $groupby;
|
$groupby = 'GROUP BY ' . $groupby;
|
||||||
if ( !empty( $orderby ) )
|
if ( !empty( $orderby ) )
|
||||||
$orderby = 'ORDER BY ' . $orderby;
|
$orderby = 'ORDER BY ' . $orderby;
|
||||||
|
|
||||||
$found_rows = '';
|
$found_rows = '';
|
||||||
if ( !$q['no_found_rows'] && !empty($limits) )
|
if ( !$q['no_found_rows'] && !empty($limits) )
|
||||||
$found_rows = 'SQL_CALC_FOUND_ROWS';
|
$found_rows = 'SQL_CALC_FOUND_ROWS';
|
||||||
@ -2265,7 +2278,24 @@ class WP_Query extends WP_Object_Query {
|
|||||||
if ( !$q['suppress_filters'] )
|
if ( !$q['suppress_filters'] )
|
||||||
$this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
|
$this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
|
||||||
|
|
||||||
|
if ( 'ids' == $q['fields'] ) {
|
||||||
|
$this->posts = $wpdb->get_col($this->request);
|
||||||
|
|
||||||
|
return $this->posts;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( 'id=>parent' == $q['fields'] ) {
|
||||||
|
$this->posts = $wpdb->get_results($this->request);
|
||||||
|
|
||||||
|
$r = array();
|
||||||
|
foreach ( $this->posts as $post )
|
||||||
|
$r[ $post->ID ] = $post->post_parent;
|
||||||
|
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
$this->posts = $wpdb->get_results($this->request);
|
$this->posts = $wpdb->get_results($this->request);
|
||||||
|
|
||||||
// Raw results filter. Prior to status checks.
|
// Raw results filter. Prior to status checks.
|
||||||
if ( !$q['suppress_filters'] )
|
if ( !$q['suppress_filters'] )
|
||||||
$this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
|
$this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user