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,7 +2902,8 @@ function &get_pages($args = '') {
'exclude' => '', 'include' => '', 'exclude' => '', 'include' => '',
'meta_key' => '', 'meta_value' => '', 'meta_key' => '', 'meta_value' => '',
'authors' => '', 'parent' => -1, 'exclude_tree' => '', 'authors' => '', 'parent' => -1, 'exclude_tree' => '',
'number' => '', 'offset' => 0 'number' => '', 'offset' => 0,
'post_type' => 'page', 'post_status' => 'publish',
); );
$r = wp_parse_args( $args, $defaults ); $r = wp_parse_args( $args, $defaults );
@ -2910,6 +2911,15 @@ function &get_pages($args = '') {
$number = (int) $number; $number = (int) $number;
$offset = (int) $offset; $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(); $cache = array();
$key = md5( serialize( compact(array_keys($defaults)) ) ); $key = md5( serialize( compact(array_keys($defaults)) ) );
if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) { if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) {
@ -3002,7 +3012,9 @@ function &get_pages($args = '') {
if ( $parent >= 0 ) if ( $parent >= 0 )
$where .= $wpdb->prepare(' AND post_parent = %d ', $parent); $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where "; $where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status );
$query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
$query .= $author_query; $query .= $author_query;
$query .= " ORDER BY " . $sort_column . " " . $sort_order ; $query .= " ORDER BY " . $sort_column . " " . $sort_order ;