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

get_category_children() WordPress Function

The get_category_children() function is used to retrieve the list of categories that are children of a given category. This function can be used in conjunction with the get_categories() function to create a hierarchical list of categories.

get_category_children( int $id, string $before = '/', string $after = '', array $visited = array() ) #

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


Description

Top ↑

See also


Top ↑

Parameters

$id

(int)(Required)Category ID to retrieve children.

$before

(string)(Optional) Prepend before category term ID.

Default value: '/'

$after

(string)(Optional) Append after category term ID.

Default value: ''

$visited

(array)(Optional) Category Term IDs that have already been added.

Default value: array()


Top ↑

Return

(string)


Top ↑

Source

File: wp-includes/deprecated.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Use get_term_children()
1.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More