WordPress.org

Make WordPress Core

Ticket #9007: category-template.diff

File category-template.diff, 1.2 KB (added by _timk, 6 years ago)

Patch: rewritten get_category_children() using get_term_children()

  • category-template.php

    old new  
    1717 * @param array $visited Optional. Category Term IDs that have already been added. 
    1818 * @return string 
    1919 */ 
    20 function get_category_children( $id, $before = '/', $after = '', $visited = array() ) { 
     20function get_category_children( $id, $before = '/', $after = '' ) { 
    2121        if ( 0 == $id ) 
    2222                return ''; 
    2323 
    24         $chain = ''; 
    25         /** TODO: consult hierarchy */ 
    26         $cat_ids = get_all_category_ids(); 
    27         foreach ( (array) $cat_ids as $cat_id ) { 
    28                 if ( $cat_id == $id ) 
    29                         continue; 
    30  
    31                 $category = get_category( $cat_id ); 
    32                 if ( is_wp_error( $category ) ) 
    33                         return $category; 
    34                 if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) { 
    35                         $visited[] = $category->term_id; 
    36                         $chain .= $before.$category->term_id.$after; 
    37                         $chain .= get_category_children( $category->term_id, $before, $after ); 
    38                 } 
    39         } 
    40         return $chain; 
     24  $children = get_term_children( $id, 'category' ); 
     25   
     26  if ( !is_wp_error( $children ) && !empty( $children ) ) 
     27    $chain = $before . join( $before . $after, $children ) . $after; 
     28  else 
     29    $chain = ''; 
     30     
     31  return $chain; 
    4132} 
    4233 
    4334/**