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
2833      if ( false !== $counts ) {
2834           // We may have cached this before every status was registered.
2835           foreach ( get_post_stati() as $status ) {
2836                if ( ! isset( $counts->{$status} ) ) {
2837                     $counts->{$status} = 0;
2838                }
2839           }
2840
2841           /** This filter is documented in wp-includes/post.php */
2842           return apply_filters( 'wp_count_posts', $counts, $type, $perm );
2843      }
2844
2845      $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
2846
2847      if ( 'readable' === $perm && is_user_logged_in() ) {
2848           $post_type_object = get_post_type_object( $type );
2849           if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
2850                $query .= $wpdb->prepare(
2851                     " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
 
Line Code
2871       *
2872       * @since 3.7.0
2873       *
2874       * @param object $counts An object containing the current post_type's post
2875       *                       counts by status.
2876       * @param string $type   Post type.
2877       * @param string $perm   The permission to determine if the posts are 'readable'
2878       *                       by the current user.
2879       */
2880      return apply_filters( 'wp_count_posts', $counts, $type, $perm );
2881 }
2882
2883 /**
2884  * Count number of attachments for the mime type(s).
2885  *
2886  * If you set the optional mime_type parameter, then an array will still be
2887  * returned, but will only have the item you are looking for. It does not give
2888  * you the number of attachments that are children of a post. You can get that
2889  * by counting the number of children that post has.