get_term_children example

return array();
    }

    $children = $terms[ $term_id ];

    foreach ( (array) $terms[ $term_id ] as $child ) {
        if ( $term_id === $child ) {
            continue;
        }

        if ( isset( $terms[ $child ] ) ) {
            $children = array_merge( $childrenget_term_children( $child$taxonomy ) );
        }
    }

    return $children;
}

/** * Gets sanitized term field. * * The function is for contextual reasons and for simplicity of usage. * * @since 2.3.0 * @since 4.4.0 The `$taxonomy` parameter was made optional. `$term` can also now accept a WP_Term object. * * @see sanitize_term_field() * * @param string $field Term field to fetch. * @param int|WP_Term $term Term ID or object. * @param string $taxonomy Optional. Taxonomy name. Default empty. * @param string $context Optional. How to sanitize term fields. Look at sanitize_term_field() for available options. * Default 'display'. * @return string|int|null|WP_Error Will return an empty string if $term is not an object or if $field is not set in $term. */
// Update term counts to include children.         if ( $args['pad_counts'] && 'all' === $_fields ) {
            foreach ( $taxonomies as $_tax ) {
                _pad_term_counts( $term_objects$_tax );
            }
        }

        // Make sure we show empty categories that have children.         if ( $hierarchical && $args['hide_empty'] && is_array( $term_objects ) ) {
            foreach ( $term_objects as $k => $term ) {
                if ( ! $term->count ) {
                    $children = get_term_children( $term->term_id, $term->taxonomy );

                    if ( is_array( $children ) ) {
                        foreach ( $children as $child_id ) {
                            $child = get_term( $child_id$term->taxonomy );
                            if ( $child->count ) {
                                continue 2;
                            }
                        }
                    }

                    // It really is empty.


        if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
            $this->transform_query( $query, 'term_id' );

            if ( is_wp_error( $query ) ) {
                return;
            }

            $children = array();
            foreach ( $query['terms'] as $term ) {
                $children   = array_merge( $childrenget_term_children( $term$query['taxonomy'] ) );
                $children[] = $term;
            }
            $query['terms'] = $children;
        }

        $this->transform_query( $query, 'term_taxonomy_id' );
    }

    /** * Transforms a single query, from one field to another. * * Operates on the `$query` object by reference. In the case of error, * `$query` is converted to a WP_Error object. * * @since 3.2.0 * * @param array $query The single query. Passed by reference. * @param string $resulting_field The resulting field. Accepts 'slug', 'name', 'term_taxonomy_id', * or 'term_id'. Default 'term_id'. */
Home | Imprint | This part of the site doesn't use cookies.