WordPress.org

Make WordPress Core

Ticket #16603: wp_count_posts_hooks.diff

File wp_count_posts_hooks.diff, 1.7 KB (added by mikeschinkel, 7 years ago)

Hooks for wp_post_counts()

  • wp-includes/post.php

     
    17931793        if ( false !== $count )
    17941794                return $count;
    17951795
    1796         $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
     1796        $query = apply_filters( 'wp_count_posts_sql', $wpdb->prepare( $query, $type ), $type, $perm );
     1797        $count = $wpdb->get_results( $query, ARRAY_A );
    17971798
    17981799        $stats = array();
    17991800        foreach ( get_post_stati() as $state )
     
    18051806        $stats = (object) $stats;
    18061807        wp_cache_set($cache_key, $stats, 'counts');
    18071808
    1808         return $stats;
     1809        return apply_filters( 'wp_count_posts', $stats, $type, $perm );
    18091810}
    18101811
    18111812
     
    50125013 * @uses wp_find_hierarchy_loop()
    50135014 *
    50145015 * @param int $post_parent ID of the parent for the post we're checking.
    5015  * @parem int $post_ID ID of the post we're checking.
     5016 * @param int $post_ID ID of the post we're checking.
    50165017 *
    50175018 * @return int The new post_parent for the post.
    50185019 */
     
    52365237}
    52375238add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
    52385239
    5239 ?>
    5240  No newline at end of file
     5240/**
     5241 * Return array of posts for post_type='page' for those pages with the given page template.
     5242 *
     5243 * @param string $template Filename of the assigned template for a page.
     5244 *
     5245 * @return array The posts that have a template matching the one passed.
     5246 */
     5247function get_pages_by_template( $template, $args ) {
     5248        global $wpdb;
     5249        $args = wp_parse_args($args,array(
     5250                'post_type' => 'page',
     5251                'posts_per_page' => -1,
     5252                'meta_key' => '_wp_page_template',
     5253                'meta_value' => $template,
     5254                'suppress_filters' => true,
     5255        ));
     5256        $result = new WP_Query($args);
     5257        return apply_filters( 'get_pages_by_template', $result->posts );
     5258}
     5259?>