wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_category_children › WordPress Function

Seit1.2.0
Veraltet2.8.0
get_category_children ( $id, $before = '/', $after = '', $visited = array() )
Parameter: (4)
  • (int) $id Category ID to retrieve children.
    Erforderlich: Ja
  • (string) $before Optional. Prepend before category term ID. Default '/'.
    Erforderlich: Nein
    Standard: '/'
  • (string) $after Optional. Append after category term ID. Default empty string.
    Erforderlich: Nein
    Standard: (leer)
  • (array) $visited Optional. Category Term IDs that have already been added. Default empty array.
    Erforderlich: Nein
    Standard: array()
Siehe:
Gibt zurück:
  • (string)
Definiert in:
Codex:

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



Quellcode

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