WordPress.org

Make WordPress Core

Ticket #16264: get_pages_by_template-v2.diff

File get_pages_by_template-v2.diff, 1.2 KB (added by mikeschinkel, 7 years ago)

Updated get_pages_by_template()

  • wp-includes/post.php

     
    50095009 * @uses wp_find_hierarchy_loop()
    50105010 *
    50115011 * @param int $post_parent ID of the parent for the post we're checking.
    5012  * @parem int $post_ID ID of the post we're checking.
     5012 * @param int $post_ID ID of the post we're checking.
    50135013 *
    50145014 * @return int The new post_parent for the post.
    50155015 */
     
    52355235}
    52365236add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
    52375237
    5238 ?>
    5239  No newline at end of file
     5238/**
     5239 * Return array of posts for post_type='page' for those pages with the given page template.
     5240 *
     5241 * @param string $template Filename of the assigned template for a page.
     5242 *
     5243 * @return array The posts that have a template matching the one passed.
     5244 */
     5245function get_pages_by_template( $template, $args ) {
     5246        global $wpdb;
     5247        $args = wp_parse_args($args,array(
     5248                'post_type' => 'page',
     5249                'posts_per_page' => -1,
     5250                'meta_key' => '_wp_page_template',
     5251                'meta_value' => $template,
     5252                'suppress_filters' => true,
     5253        ));
     5254        $result = new WP_Query($args);
     5255        return apply_filters( 'get_pages_by_template', $result->posts );
     5256}
     5257?>