From ba59fac7080f7dac0e722fcef5f73093fbaf6474 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 9 Jul 2014 18:16:15 +0000 Subject: [PATCH] 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 --- wp-includes/comment.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index dd45821c34..33a6121fd2 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -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.