From 3cf21a917835fbf9be0d7152ee01ad92f9150795 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sat, 13 Mar 2010 20:01:02 +0000 Subject: [PATCH] Add custom hierarchical post type support to get_pages(). Props ptahdunbar. see #12600 git-svn-id: https://develop.svn.wordpress.org/trunk@13695 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/post.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index ccf14ce60d..615db26b06 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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 ;