Advertisements

get_category_children

Definition:
function get_category_children( $id, $before = '/', $after = '', $visited = array() {}

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

Parameters

  • int $id: Category ID to retrieve children.
  • string $before: Optional. Prepend before category term ID.
  • string $after: Optional, default is empty string. Append after category term ID.
  • array $visited: Optional. Category Term IDs that have already been added.

Source code

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;

}

1248

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: