WordPress.org

Make WordPress Core

Ticket #10277: category.php.r12462.diff

File category.php.r12462.diff, 847 bytes (added by bi0xid, 11 years ago)

Category with get_root_category

  • trunk/wp-includes/category.php

    a b  
    175175/**
    176176 * Retrieve the name of a category from its ID.
    177177 *
    178178 * @since 1.0.0
    179179 *
    180180 * @param int $cat_id Category ID
    181181 * @return string Category name
    182182 */
    183183function get_cat_name( $cat_id ) {
    184184        $cat_id = (int) $cat_id;
    185185        $category = &get_category( $cat_id );
    186186        return $category->name;
    187187}
    188188
     189 function get_category_root($cat_id = 0) {
     190         $category_parent = get_category($cat_id);
     191         while( ! empty( $category_parent->category_parent ) ) {
     192                 $category_parent = get_category($category_parent->category_parent);
     193         }   
     194         return ! empty( $category_parent->term_id ) ? $category_parent->term_id : $cat_id;
     195 }