WP_Comment_Query: comment__in, comment__not_in, post__in, post__not_in.

Props nofearinc, mordauk, boonebgorges

Fixes #25386
Built from https://develop.svn.wordpress.org/trunk@29808


git-svn-id: http://core.svn.wordpress.org/trunk@29574 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2014-10-02 01:41:16 +00:00
parent be631b3f1b
commit 7d8322aa65
1 changed files with 26 additions and 0 deletions

View File

@ -257,6 +257,8 @@ class WP_Comment_Query {
* Execute the query * Execute the query
* *
* @since 3.1.0 * @since 3.1.0
* @since 4.1.0 Introduced 'comment__in', 'comment__not_in',
* 'post__in', and 'post__not_in' to $query_vars.
* *
* @param string|array $query_vars * @param string|array $query_vars
* @return int|array * @return int|array
@ -268,6 +270,8 @@ class WP_Comment_Query {
'author_email' => '', 'author_email' => '',
'fields' => '', 'fields' => '',
'ID' => '', 'ID' => '',
'comment__in' => '',
'comment__not_in' => '',
'karma' => '', 'karma' => '',
'number' => '', 'number' => '',
'offset' => '', 'offset' => '',
@ -276,6 +280,8 @@ class WP_Comment_Query {
'parent' => '', 'parent' => '',
'post_ID' => '', 'post_ID' => '',
'post_id' => 0, 'post_id' => 0,
'post__in' => '',
'post__not_in' => '',
'post_author' => '', 'post_author' => '',
'post_name' => '', 'post_name' => '',
'post_parent' => '', 'post_parent' => '',
@ -408,6 +414,26 @@ class WP_Comment_Query {
$where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id ); $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
} }
// Parse comment IDs for an IN clause.
if ( ! empty( $this->query_vars['comment__in'] ) ) {
$where .= ' AND comment_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
}
// Parse comment IDs for a NOT IN clause.
if ( ! empty( $this->query_vars['comment__not_in'] ) ) {
$where .= ' AND comment_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
}
// Parse comment post IDs for an IN clause.
if ( ! empty( $this->query_vars['post__in'] ) ) {
$where .= ' AND comment_post_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__in'] ) ) . ' )';
}
// Parse comment post IDs for a NOT IN clause.
if ( ! empty( $this->query_vars['post__not_in'] ) ) {
$where .= ' AND comment_post_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__not_in'] ) ) . ' )';
}
if ( '' !== $this->query_vars['author_email'] ) { if ( '' !== $this->query_vars['author_email'] ) {
$where .= $wpdb->prepare( ' AND comment_author_email = %s', $this->query_vars['author_email'] ); $where .= $wpdb->prepare( ' AND comment_author_email = %s', $this->query_vars['author_email'] );
} }