Welcome, visitor! Log in
 

Source View: wp_count_comments

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN  (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

  • Action hooks look like this: do_action( "hook_name" )
  • Filter hooks look like this: apply_filters( "hook_name", "what_to_filter" ).

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

Line Code
670   * property contains the integer of total comments.
671   *
672   * The comment stats are cached and then retrieved, if they already exist in the
673   * cache.
674   *
675   * @since 2.5.0
676   *
677   * @param int $post_id Optional. Post ID.
678   * @return object Comment stats.
679   */
680  function wp_count_comments( $post_id = 0 ) {
681       global $wpdb;
682  
683       $post_id = (int) $post_id;
684  
685       $stats = apply_filters('wp_count_comments', array(), $post_id);
686       if ( !empty($stats) )
687            return $stats;
688  
689       $count = wp_cache_get("comments-{$post_id}", 'counts');
690  
691       if ( false !== $count )
692            return $count;
693  
694       $where = '';
695       if( $post_id > 0 )
696            $where = $wpdb->prepare( "WHERE comment_post_ID = %d", $post_id );
697  
698       $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
699  
700       $total = 0;