Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: wp_count_posts

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.

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

Source View

This hook occurs 2 times in this file.

Line Code
3128      if ( false !== $counts ) {
3129           // We may have cached this before every status was registered.
3130           foreach ( get_post_stati() as $status ) {
3131                if ( ! isset( $counts->{$status} ) ) {
3132                     $counts->{$status} = 0;
3133                }
3134           }
3135
3136           /** This filter is documented in wp-includes/post.php */
3137           return apply_filters( 'wp_count_posts', $counts, $type, $perm );
3138      }
3139
3140      $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
3141
3142      if ( 'readable' === $perm && is_user_logged_in() ) {
3143           $post_type_object = get_post_type_object( $type );
3144           if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
3145                $query .= $wpdb->prepare(
3146                     " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
 
Line Code
3166       *
3167       * @since 3.7.0
3168       *
3169       * @param stdClass $counts An object containing the current post_type's post
3170       *                         counts by status.
3171       * @param string   $type   Post type.
3172       * @param string   $perm   The permission to determine if the posts are 'readable'
3173       *                         by the current user.
3174       */
3175      return apply_filters( 'wp_count_posts', $counts, $type, $perm );
3176 }
3177
3178 /**
3179  * Counts number of attachments for the mime type(s).
3180  *
3181  * If you set the optional mime_type parameter, then an array will still be
3182  * returned, but will only have the item you are looking for. It does not give
3183  * you the number of attachments that are children of a post. You can get that
3184  * by counting the number of children that post has.