297 | | $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE $post_where $approved ORDER BY $orderby $order $number" ); |
| 299 | if ( ! empty( $post_status ) ) { |
| 300 | $post_status = is_array( $post_status ) ? $post_status : preg_split( '/[,\s]/', $post_status ); |
| 301 | if ( array_intersect( $post_status, get_post_stati() ) ) |
| 302 | $post_status = stripslashes( $wpdb->prepare( "AND post_status IN ( '%s' )", implode( "','", $post_status ) ) ); |
| 303 | } |
| 304 | |
| 305 | if ( ! empty( $post_type ) ) { |
| 306 | $post_type = is_array( $post_type ) ? $post_type : preg_split( '/[,\s]/', $post_type ); |
| 307 | if ( array_intersect( $post_type, get_post_types() ) ) |
| 308 | $post_type = stripslashes( $wpdb->prepare( "AND post_type IN ( '%s' )", implode( "','", $post_type ) ) ); |
| 309 | } |
| 310 | |
| 311 | $join = ''; |
| 312 | |
| 313 | if ( ! empty( $post_status ) || ! empty( $post_type ) ) |
| 314 | $join = $wpdb->prepare( "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID" ); |
| 315 | |
| 316 | $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments $join WHERE $post_where $approved $post_status $post_type ORDER BY $orderby $order $number" ); |