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

git-svn-id: http://svn.automattic.com/wordpress/trunk@13695 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-03-13 20:01:02 +00:00
parent f3707c7791
commit 63302cae08
1 changed files with 14 additions and 2 deletions

View File

@ -2902,13 +2902,23 @@ function &get_pages($args = '') {
'exclude' => '', 'include' => '',
'meta_key' => '', 'meta_value' => '',
'authors' => '', 'parent' => -1, 'exclude_tree' => '',
'number' => '', 'offset' => 0
'number' => '', 'offset' => 0,
'post_type' => 'page', 'post_status' => 'publish',
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$number = (int) $number;
$offset = (int) $offset;
// Make sure the post type is hierarchical
$hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
if ( !in_array( $post_type, $hierarchical_post_types ) )
return false;
// Make sure we have a valid post status
if ( !in_array($post_status, get_post_stati()) )
return false;
$cache = array();
$key = md5( serialize( compact(array_keys($defaults)) ) );
@ -3001,8 +3011,10 @@ function &get_pages($args = '') {
if ( $parent >= 0 )
$where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
$where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status );
$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where ";
$query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
$query .= $author_query;
$query .= " ORDER BY " . $sort_column . " " . $sort_order ;