get_category_children

The timeline below displays how wordpress function get_category_children has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 * @deprecated 2.8.0 Use get_term_children()
 * @see get_term_children()
 *
 * @param int    $id      Category ID to retrieve children.
 * @param string $before  Optional. Prepend before category term ID. Default '/'.
 * @param string $after   Optional. Append after category term ID. Default empty string.
 * @param array  $visited Optional. Category Term IDs that have already been added.
 *                        Default empty array.
 * @return string
 */
function get_category_children($id, $before = '/', $after = '', $visited = array())
{
    _deprecated_function(__FUNCTION__, '2.8.0', 'get_term_children()');
    if (0 == $id) {
        return '';
    }
    $chain = '';
    /** TODO: Consult hierarchy */
    $cat_ids = get_all_category_ids();
    foreach ((array) $cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id && !in_array($category->term_id, $visited)) {
            $visited[] = $category->term_id;
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}

WordPress Version: 5.4

/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 * @deprecated 2.8.0 Use get_term_children()
 * @see get_term_children()
 *
 * @param int $id Category ID to retrieve children.
 * @param string $before Optional. Prepend before category term ID.
 * @param string $after Optional, default is empty string. Append after category term ID.
 * @param array $visited Optional. Category Term IDs that have already been added.
 * @return string
 */
function get_category_children($id, $before = '/', $after = '', $visited = array())
{
    _deprecated_function(__FUNCTION__, '2.8.0', 'get_term_children()');
    if (0 == $id) {
        return '';
    }
    $chain = '';
    /** TODO: Consult hierarchy */
    $cat_ids = get_all_category_ids();
    foreach ((array) $cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id && !in_array($category->term_id, $visited)) {
            $visited[] = $category->term_id;
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}

WordPress Version: 4.6

/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 * @deprecated 2.8.0 Use get_term_children()
 * @see get_term_children()
 *
 * @param int $id Category ID to retrieve children.
 * @param string $before Optional. Prepend before category term ID.
 * @param string $after Optional, default is empty string. Append after category term ID.
 * @param array $visited Optional. Category Term IDs that have already been added.
 * @return string
 */
function get_category_children($id, $before = '/', $after = '', $visited = array())
{
    _deprecated_function(__FUNCTION__, '2.8.0', 'get_term_children()');
    if (0 == $id) {
        return '';
    }
    $chain = '';
    /** TODO: consult hierarchy */
    $cat_ids = get_all_category_ids();
    foreach ((array) $cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id && !in_array($category->term_id, $visited)) {
            $visited[] = $category->term_id;
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}

WordPress Version: 4.4

/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 * @deprecated 2.8.0 Use get_term_children()
 * @see get_term_children()
 *
 * @param int $id Category ID to retrieve children.
 * @param string $before Optional. Prepend before category term ID.
 * @param string $after Optional, default is empty string. Append after category term ID.
 * @param array $visited Optional. Category Term IDs that have already been added.
 * @return string
 */
function get_category_children($id, $before = '/', $after = '', $visited = array())
{
    _deprecated_function(__FUNCTION__, '2.8', 'get_term_children()');
    if (0 == $id) {
        return '';
    }
    $chain = '';
    /** TODO: consult hierarchy */
    $cat_ids = get_all_category_ids();
    foreach ((array) $cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id && !in_array($category->term_id, $visited)) {
            $visited[] = $category->term_id;
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}

WordPress Version: 3.9

/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 * @deprecated 2.8.0
 * @deprecated Use get_term_children()
 * @see get_term_children()
 *
 * @param int $id Category ID to retrieve children.
 * @param string $before Optional. Prepend before category term ID.
 * @param string $after Optional, default is empty string. Append after category term ID.
 * @param array $visited Optional. Category Term IDs that have already been added.
 * @return string
 */
function get_category_children($id, $before = '/', $after = '', $visited = array())
{
    _deprecated_function(__FUNCTION__, '2.8', 'get_term_children()');
    if (0 == $id) {
        return '';
    }
    $chain = '';
    /** TODO: consult hierarchy */
    $cat_ids = get_all_category_ids();
    foreach ((array) $cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id && !in_array($category->term_id, $visited)) {
            $visited[] = $category->term_id;
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}

WordPress Version: 3.7

/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 * @deprecated 2.8
 * @deprecated Use get_term_children()
 * @see get_term_children()
 *
 * @param int $id Category ID to retrieve children.
 * @param string $before Optional. Prepend before category term ID.
 * @param string $after Optional, default is empty string. Append after category term ID.
 * @param array $visited Optional. Category Term IDs that have already been added.
 * @return string
 */
function get_category_children($id, $before = '/', $after = '', $visited = array())
{
    _deprecated_function(__FUNCTION__, '2.8', 'get_term_children()');
    if (0 == $id) {
        return '';
    }
    $chain = '';
    /** TODO: consult hierarchy */
    $cat_ids = get_all_category_ids();
    foreach ((array) $cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id && !in_array($category->term_id, $visited)) {
            $visited[] = $category->term_id;
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}