WordPress.org

Make WordPress Core

Ticket #12600: get_pages.diff

File get_pages.diff, 1.4 KB (added by ptahdunbar, 8 years ago)
  • post.php

     
    29022902                'exclude' => '', 'include' => '',
    29032903                'meta_key' => '', 'meta_value' => '',
    29042904                'authors' => '', 'parent' => -1, 'exclude_tree' => '',
    2905                 'number' => '', 'offset' => 0
     2905                'number' => '', 'offset' => 0,
     2906                'post_type' => 'page', 'post_status' => 'publish',
    29062907        );
    29072908
    29082909        $r = wp_parse_args( $args, $defaults );
    29092910        extract( $r, EXTR_SKIP );
    29102911        $number = (int) $number;
    29112912        $offset = (int) $offset;
     2913       
     2914        // Make sure the post type is hierarchical
     2915        $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
     2916        if ( !in_array( $post_type, $hierarchical_post_types ) )
     2917                return false;
     2918       
     2919        // Make sure we have a valid post status
     2920        if ( !in_array($post_status, get_post_stati()) )
     2921                return false;
    29122922
    29132923        $cache = array();
    29142924        $key = md5( serialize( compact(array_keys($defaults)) ) );
     
    30013011
    30023012        if ( $parent >= 0 )
    30033013                $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
     3014               
     3015        $where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status );
    30043016
    3005         $query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where ";
     3017        $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
    30063018        $query .= $author_query;
    30073019        $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
    30083020