Use table prefix for comment__in
and comment__not_in
SQL clauses of WP_Comment_Query
.
The prefix prevents ambiguity when joining against other tables. Props willgladstone. Fixes #32081. git-svn-id: https://develop.svn.wordpress.org/trunk@32461 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c8ca3c2304
commit
637bedeece
@ -696,12 +696,12 @@ class WP_Comment_Query {
|
||||
|
||||
// Parse comment IDs for an IN clause.
|
||||
if ( ! empty( $this->query_vars['comment__in'] ) ) {
|
||||
$where[] = 'comment_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
|
||||
$where[] = "$wpdb->comments.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[] = 'comment_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
|
||||
$where[] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
|
||||
}
|
||||
|
||||
// Parse comment post IDs for an IN clause.
|
||||
|
@ -722,6 +722,53 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$this->assertEquals( array( $comments[2], $comments[0], $comments[1] ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 32081
|
||||
*/
|
||||
public function test_meta_query_should_work_with_comment__in() {
|
||||
$comments = $this->factory->comment->create_many( 3 );
|
||||
|
||||
add_comment_meta( $comments[0], 'foo', 'jjj' );
|
||||
add_comment_meta( $comments[1], 'foo', 'zzz' );
|
||||
add_comment_meta( $comments[2], 'foo', 'jjj' );
|
||||
|
||||
$q = new WP_Comment_Query( array(
|
||||
'comment__in' => array( $comments[1], $comments[2] ),
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'foo',
|
||||
'value' => 'jjj',
|
||||
),
|
||||
),
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEquals( array( $comments[2] ), $q->get_comments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 32081
|
||||
*/
|
||||
public function test_meta_query_should_work_with_comment__not_in() {
|
||||
$comments = $this->factory->comment->create_many( 3 );
|
||||
|
||||
add_comment_meta( $comments[0], 'foo', 'jjj' );
|
||||
add_comment_meta( $comments[1], 'foo', 'zzz' );
|
||||
add_comment_meta( $comments[2], 'foo', 'jjj' );
|
||||
|
||||
$q = new WP_Comment_Query( array(
|
||||
'comment__not_in' => array( $comments[1], $comments[2] ),
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'foo',
|
||||
'value' => 'jjj',
|
||||
),
|
||||
),
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEquals( array( $comments[0] ), $q->get_comments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 27064
|
||||
|
Loading…
Reference in New Issue
Block a user