diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 08919f3158..3dea3be15b 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -213,6 +213,11 @@ class WP_Comment_Query { 'parent' => '', 'post_ID' => '', 'post_id' => 0, + 'post_author' => '', + 'post_name' => '', + 'post_parent' => '', + 'post_status' => '', + 'post_type' => '', 'status' => '', 'type' => '', 'user_id' => '', @@ -319,6 +324,13 @@ class WP_Comment_Query { if ( '' !== $search ) $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) ); + $post_fields = array_filter( compact( array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type', ) ) ); + if ( ! empty( $post_fields ) ) { + $join = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID"; + foreach( $post_fields as $field_name => $field_value ) + $where .= $wpdb->prepare( " AND {$wpdb->posts}.{$field_name} = %s", $field_value ); + } + $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' ); $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) ); foreach ( $pieces as $piece ) diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index 8f3ad310f7..dc1c9ec880 100644 --- a/wp-includes/default-widgets.php +++ b/wp-includes/default-widgets.php @@ -640,7 +640,7 @@ class WP_Widget_Recent_Comments extends WP_Widget { if ( ! $number = absint( $instance['number'] ) ) $number = 5; - $comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) ); + $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ); $output .= $before_widget; if ( $title ) $output .= $before_title . $title . $after_title;