diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 6c74991e6a..cf024bcdd0 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -85,26 +85,27 @@ function sort_cats( $cat1, $cat2 ) { } function get_nested_categories( $default = 0, $parent = 0 ) { - global $post_ID, $mode, $wpdb; + global $post_ID, $mode, $wpdb, $checked_categories; - if ( $post_ID ) { - $checked_categories = wp_get_post_categories($post_ID); + if ( empty($checked_categories) ) { + if ( $post_ID ) { + $checked_categories = wp_get_post_categories($post_ID); - if ( count( $checked_categories ) == 0 ) { - // No selected categories, strange + if ( count( $checked_categories ) == 0 ) { + // No selected categories, strange + $checked_categories[] = $default; + } + } else { $checked_categories[] = $default; } - } else { - $checked_categories[] = $default; } $cats = get_categories("child_of=$parent&hide_empty=0&fields=ids"); - $result = array (); + $result = array (); if ( is_array( $cats ) ) { foreach ( $cats as $cat) { - // TODO fix hierarchy - //$result[$cat]['children'] = get_nested_categories( $default, $cat); + $result[$cat]['children'] = get_nested_categories( $default, $cat); $result[$cat]['cat_ID'] = $cat; $result[$cat]['checked'] = in_array( $cat, $checked_categories ); $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 6f9e5ae794..19c405c228 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -407,7 +407,7 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) { */ function get_object_terms($object_ids, $taxonomies, $args = array()) { global $wpdb; - + error_log("Objects: " . var_export($object_ids, true), 0); if ( !is_array($taxonomies) ) $taxonomies = array($taxonomies); @@ -482,6 +482,12 @@ function &get_terms($taxonomies, $args = '') { } extract($args); + if ( $child_of ) { + $hierarchy = _get_term_hierarchy($taxonomies[0]); + if ( !isset($hierarchy[$child_of]) ) + return array(); + } + $key = md5( serialize( $args ) . serialize( $taxonomies ) ); if ( $cache = wp_cache_get( 'get_terms', 'terms' ) ) { if ( isset( $cache[ $key ] ) )