get_category_children( int $id, string $before = ‘/’, string $after = , array $visited = array() ): string

This function has been deprecated. Use get_term_children() instead.

Retrieve category children list separated before and after the term IDs.

Description

See also

Parameters

$idintrequired
Category ID to retrieve children.
$beforestringoptional
Prepend before category term ID. Default '/'.

Default:'/'

$afterstringoptional
Append after category term ID.

Default:''

$visitedarrayoptional
Category Term IDs that have already been added.

Default:array()

Return

string

Source

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;
}

Changelog

VersionDescription
2.8.0Use get_term_children()
1.2.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    If attempting to replace this deprecated function with get_term_children() , note that get_category_children() returns a String, while get_term_children() returns an array of Category IDs. Also note that get_term_children() requires a second parameter of ‘category’, which is the name of the pre-defined Taxonomy for Categories.

You must log in before being able to contribute a note or feedback.