Make WordPress Core

Changeset 13695


Ignore:
Timestamp:
03/13/2010 08:01:02 PM (15 years ago)
Author:
ryan
Message:

Add custom hierarchical post type support to get_pages(). Props ptahdunbar. see #12600

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r13653 r13695  
    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
     
    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();
     
    30023012    if ( $parent >= 0 )
    30033013        $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
    3004 
    3005     $query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where ";
     3014       
     3015    $where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status );
     3016
     3017    $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
    30063018    $query .= $author_query;
    30073019    $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
Note: See TracChangeset for help on using the changeset viewer.