get_term_field

Advertisement

Summery Summery

Get sanitized Term field.

Syntax Syntax

get_term_field( string $field, int|WP_Term $term, string $taxonomy = '', string $context = 'display' )

Description Description

The function is for contextual reasons and for simplicity of usage.

Parameters Parameters

$field

(Required) Term field to fetch.

$term

(Required) Term ID or object.

$taxonomy

(Optional) Taxonomy Name.

Default value: ''

$context

(Optional) default is display. Look at sanitize_term_field() for available options.

Default value: 'display'

Return 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.

Source Source

File: wp-includes/taxonomy.php

	$terms = _get_term_hierarchy( $taxonomy );

	if ( ! isset( $terms[ $term_id ] ) ) {
		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( $children, get_term_children( $child, $taxonomy ) );

Advertisement

Changelog Changelog

Changelog
Version Description
4.4.0 The $taxonomy parameter was made optional. $term can also now accept a WP_Term object.
2.3.0 Introduced.

See also See also

Advertisement

Leave a Reply