mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-22 07:22:01 +01:00
Allow comments to be queried by 'any' post_type
or post_status
.
Props kouratoras. Fixes #35512. Built from https://develop.svn.wordpress.org/trunk@36486 git-svn-id: http://core.svn.wordpress.org/trunk@36453 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
fe1dd15126
commit
146320744f
@ -220,10 +220,11 @@ class WP_Comment_Query {
|
||||
* @type array $post__not_in Array of post IDs to exclude affiliated comments for.
|
||||
* Default empty.
|
||||
* @type int $post_author Post author ID to limit results by. Default empty.
|
||||
* @type string $post_status Post status to retrieve affiliated comments for.
|
||||
* Default empty.
|
||||
* @type string $post_type Post type to retrieve affiliated comments for.
|
||||
* @type string|array $post_status Post status or array of post statuses to retrieve
|
||||
* affiliated comments for. Pass 'any' to match any value.
|
||||
* Default empty.
|
||||
* @type string $post_type Post type or array of post types to retrieve affiliated
|
||||
* comments for. Pass 'any' to match any value. Default empty.
|
||||
* @type string $post_name Post name to retrieve affiliated comments for.
|
||||
* Default empty.
|
||||
* @type int $post_parent Post parent ID to retrieve affiliated comments for.
|
||||
@ -760,7 +761,7 @@ class WP_Comment_Query {
|
||||
|
||||
// If any post-related query vars are passed, join the posts table.
|
||||
$join_posts_table = false;
|
||||
$plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type' ) );
|
||||
$plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) );
|
||||
$post_fields = array_filter( $plucked );
|
||||
|
||||
if ( ! empty( $post_fields ) ) {
|
||||
@ -772,6 +773,27 @@ class WP_Comment_Query {
|
||||
}
|
||||
}
|
||||
|
||||
// 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'.
|
||||
foreach ( array( 'post_status', 'post_type' ) as $field_name ) {
|
||||
$q_values = array();
|
||||
if ( ! empty( $this->query_vars[ $field_name ] ) ) {
|
||||
$q_values = $this->query_vars[ $field_name ];
|
||||
if ( ! is_array( $q_values ) ) {
|
||||
$q_values = explode( ',', $q_values );
|
||||
}
|
||||
|
||||
// 'any' will cause the query var to be ignored.
|
||||
if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$join_posts_table = true;
|
||||
|
||||
$esses = array_fill( 0, count( $q_values ), '%s' );
|
||||
$this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values );
|
||||
}
|
||||
}
|
||||
|
||||
// Comment author IDs for an IN clause.
|
||||
if ( ! empty( $this->query_vars['author__in'] ) ) {
|
||||
$this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__in'] ) ) . ' )';
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.5-alpha-36485';
|
||||
$wp_version = '4.5-alpha-36486';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user