Make WordPress Core


Ignore:
Timestamp:
10/29/2014 09:57:07 PM (9 years ago)
Author:
boonebgorges
Message:

Use WP_Comment_Query to query comments in get_approved_comments().

Props dancameron.
See #12668.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r30096 r30098  
    129129 *
    130130 * @since 2.0.0
    131  * @uses $wpdb
    132  *
    133  * @param int $post_id The ID of the post
    134  * @return array $comments The approved comments
    135  */
    136 function get_approved_comments($post_id) {
    137     global $wpdb;
    138     return $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post_id));
     131 *
     132 * @param  int   $post_id  The ID of the post.
     133 * @param  array $args     Optional. WP_Comment_Query args.
     134 * @return array $comments The approved comments.
     135 */
     136function get_approved_comments( $post_id = 0, $args = array() ) {
     137    $defaults = array(
     138        'status'  => 1,
     139        'post_id' => $post_id,
     140        'order'   => 'ASC',
     141    );
     142    $r = wp_parse_args( $args, $defaults );
     143
     144    $query = new WP_Comment_Query;
     145    return $query->query( $r );
    139146}
    140147
Note: See TracChangeset for help on using the changeset viewer.