Opened 9 years ago
Closed 9 years ago
#35478 closed defect (bug) (fixed)
4.4 Regression on Querying for Comments by Multiple Post Fields
Reported by: | chriscct7 | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.4.2 | Priority: | high |
Severity: | major | Version: | 4.4 |
Component: | Comments | Keywords: | fixed-major |
Focuses: | Cc: |
Description
In 4.4, there has been a regression in using WP_Comment_Query, and querying by multiple post field parameters no longer works.
The cause is this loop that now processes post_fields:
if ( ! empty( $post_fields ) ) { $join_posts_table = true; foreach ( $post_fields as $field_name => $field_value ) { // $field_value may be an array. $esses = array_fill( 0, count( (array) $field_value ), '%s' ); $this->sql_clauses['where']['post_fields'] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value ); } }
On each iteration of this loop, the previous post_field query is thrown out.
Thus a comment query by post_author and post_type will ignore the post_author limiter.
This is caused by [34542] where before each forloop iteration resulted in a new array index. Post [34542] this is not the case, causing the bug.
Additionally the docbloc on post_author is incorrect:
Comment author ID to limit results by. Default empty.
it should read
Post author ID to limit results by. Default empty.
Change History (4)
Note: See
TracTickets for help on using
tickets.
I think what can be done is change
$this->sql_clauses['where']['post_fields']
to$this->sql_clauses['where'][ $field_name ]