get_approved_comments

Retrieve the approved comments for post $post_id.

Description

(int|array) get_approved_comments( (int) $post_id, (array) $args = array() ); 

Returns (int|array)

$comments The approved comments, or number of comments if `$count` argument is true.

Parameters (2)

0. $post_id (int)
The ID of the post.
1. $args — Optional. (array) => array()
See WP_Comment_Query::query() for information on accepted arguments.

Usage

  1. if ( !function_exists( 'get_approved_comments' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // The ID of the post. 
  5. $post_id = -1; 
  6.  
  7. // Optional. See WP_Comment_Query::query() for information on accepted arguments. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_approved_comments($post_id, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function get_approved_comments( $post_id, $args = array() ) { 
  2. if ( ! $post_id ) { 
  3. return array(); 
  4.  
  5. $defaults = array( 
  6. 'status' => 1,  
  7. 'post_id' => $post_id,  
  8. 'order' => 'ASC',  
  9. ); 
  10. $r = wp_parse_args( $args, $defaults ); 
  11.  
  12. $query = new WP_Comment_Query; 
  13. return $query->query( $r );