WP_Comment_Query: Add fields => 'ids' query var.

props mordauk.
fixes #28434.

Built from https://develop.svn.wordpress.org/trunk@29045


git-svn-id: http://core.svn.wordpress.org/trunk@28833 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-07-09 18:16:15 +00:00
parent ef436cb6e0
commit ba59fac708
1 changed files with 16 additions and 1 deletions

View File

@ -245,6 +245,7 @@ class WP_Comment_Query {
$defaults = array(
'author_email' => '',
'fields' => '',
'ID' => '',
'karma' => '',
'number' => '',
@ -368,8 +369,16 @@ class WP_Comment_Query {
if ( $this->query_vars['count'] ) {
$fields = 'COUNT(*)';
} else {
$fields = '*';
switch ( strtolower( $this->query_vars['fields'] ) ) {
case 'ids':
$fields = "$wpdb->comments.comment_ID";
break;
default:
$fields = "*";
break;
}
}
$join = '';
$where = $approved;
@ -460,6 +469,12 @@ class WP_Comment_Query {
if ( $this->query_vars['count'] ) {
return $wpdb->get_var( $query );
}
if ( 'ids' == $this->query_vars['fields'] ) {
$this->comments = $wpdb->get_col( $query );
return array_map( 'intval', $this->comments );
}
$results = $wpdb->get_results( $query );
/**
* Filter the comment query results.