If a term has no children, return an empty array for child_of queries. see #4189
git-svn-id: http://svn.automattic.com/wordpress/trunk@5612 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d268eae391
commit
e7e4c113fd
|
@ -85,26 +85,27 @@ function sort_cats( $cat1, $cat2 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_nested_categories( $default = 0, $parent = 0 ) {
|
function get_nested_categories( $default = 0, $parent = 0 ) {
|
||||||
global $post_ID, $mode, $wpdb;
|
global $post_ID, $mode, $wpdb, $checked_categories;
|
||||||
|
|
||||||
if ( $post_ID ) {
|
if ( empty($checked_categories) ) {
|
||||||
$checked_categories = wp_get_post_categories($post_ID);
|
if ( $post_ID ) {
|
||||||
|
$checked_categories = wp_get_post_categories($post_ID);
|
||||||
|
|
||||||
if ( count( $checked_categories ) == 0 ) {
|
if ( count( $checked_categories ) == 0 ) {
|
||||||
// No selected categories, strange
|
// No selected categories, strange
|
||||||
|
$checked_categories[] = $default;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$checked_categories[] = $default;
|
$checked_categories[] = $default;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$checked_categories[] = $default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$cats = get_categories("child_of=$parent&hide_empty=0&fields=ids");
|
$cats = get_categories("child_of=$parent&hide_empty=0&fields=ids");
|
||||||
$result = array ();
|
|
||||||
|
|
||||||
|
$result = array ();
|
||||||
if ( is_array( $cats ) ) {
|
if ( is_array( $cats ) ) {
|
||||||
foreach ( $cats as $cat) {
|
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]['cat_ID'] = $cat;
|
||||||
$result[$cat]['checked'] = in_array( $cat, $checked_categories );
|
$result[$cat]['checked'] = in_array( $cat, $checked_categories );
|
||||||
$result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
|
$result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
|
||||||
|
|
|
@ -407,7 +407,7 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) {
|
||||||
*/
|
*/
|
||||||
function get_object_terms($object_ids, $taxonomies, $args = array()) {
|
function get_object_terms($object_ids, $taxonomies, $args = array()) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
error_log("Objects: " . var_export($object_ids, true), 0);
|
||||||
if ( !is_array($taxonomies) )
|
if ( !is_array($taxonomies) )
|
||||||
$taxonomies = array($taxonomies);
|
$taxonomies = array($taxonomies);
|
||||||
|
|
||||||
|
@ -482,6 +482,12 @@ function &get_terms($taxonomies, $args = '') {
|
||||||
}
|
}
|
||||||
extract($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 ) );
|
$key = md5( serialize( $args ) . serialize( $taxonomies ) );
|
||||||
if ( $cache = wp_cache_get( 'get_terms', 'terms' ) ) {
|
if ( $cache = wp_cache_get( 'get_terms', 'terms' ) ) {
|
||||||
if ( isset( $cache[ $key ] ) )
|
if ( isset( $cache[ $key ] ) )
|
||||||
|
|
Loading…
Reference in New Issue