From 7d8322aa65f5d8e352c1847627982091b2e29241 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 2 Oct 2014 01:41:16 +0000 Subject: [PATCH] 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 --- wp-includes/comment.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 7c425744bd..57eaaada3f 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -257,6 +257,8 @@ class WP_Comment_Query { * Execute the query * * @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 * @return int|array @@ -268,6 +270,8 @@ class WP_Comment_Query { 'author_email' => '', 'fields' => '', 'ID' => '', + 'comment__in' => '', + 'comment__not_in' => '', 'karma' => '', 'number' => '', 'offset' => '', @@ -276,6 +280,8 @@ class WP_Comment_Query { 'parent' => '', 'post_ID' => '', 'post_id' => 0, + 'post__in' => '', + 'post__not_in' => '', 'post_author' => '', 'post_name' => '', 'post_parent' => '', @@ -408,6 +414,26 @@ class WP_Comment_Query { $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'] ) { $where .= $wpdb->prepare( ' AND comment_author_email = %s', $this->query_vars['author_email'] ); }