WP_Comment_Query: comment__in, comment__not_in, post__in, post__not_in.

Props nofearinc, mordauk, boonebgorges

Fixes #25386

git-svn-id: https://develop.svn.wordpress.org/trunk@29808 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2014-10-02 01:40:56 +00:00
parent c313878af2
commit dd9e9501c1
2 changed files with 98 additions and 0 deletions
+26
View File
@@ -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'] );
}