get_category_children
Retrieve category children list separated before and after the term IDs.
Description
(string) get_category_children( (int) $id, (string) $before = '/', (string) $after = '', (array) $visited = array() );
Returns (string)
Parameters (4)
- 0. $id (int)
- Category ID to retrieve children.
- 1. $before — Optional. (string) =>
'/'
- Prepend before category term ID.
- 2. $after — Optional. (string) =>
''
- Optional, default is empty string. Append after category term ID.
- 3. $visited — Optional. (array) =>
array()
- Category Term IDs that have already been added.
Usage
if ( !function_exists( 'get_category_children' ) ) { require_once ABSPATH . WPINC . '/deprecated.php'; } // Category ID to retrieve children. $id = -1; // Optional. Prepend before category term ID. $before = '/'; // Optional, default is empty string. Append after category term ID. $after = ''; // Optional. Category Term IDs that have already been added. $visited = array(); // NOTICE! Understand what this does before running. $result = get_category_children($id, $before, $after, $visited);
Defined (1)
The function is defined in the following location(s).
- /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;
- }