wppaste
WordPress

WP_Term_Query::format_terms( WP_Term[] $term_objects, string $_fields ): WP_Term[]|int[]|string[]

Since
6.0.0
Source
wp-includes/class-wp-term-query.php:977
Format response depending on field requested.

Parameters

$term_objectsWP_Term[]
Array of term objects.
$_fieldsstring
Field to format.

Return

WP_Term[]|int[]|string[]
Array of terms / strings / ints depending on field requested.

Used by · 1

Source

	protected function format_terms( $term_objects, $_fields ) {		$_terms = array();		if ( 'id=>parent' === $_fields ) {			foreach ( $term_objects as $term ) {				$_terms[ $term->term_id ] = $term->parent;			}		} elseif ( 'ids' === $_fields ) {			foreach ( $term_objects as $term ) {				$_terms[] = (int) $term->term_id;			}		} elseif ( 'tt_ids' === $_fields ) {			foreach ( $term_objects as $term ) {				$_terms[] = (int) $term->term_taxonomy_id;			}		} elseif ( 'names' === $_fields ) {			foreach ( $term_objects as $term ) {				$_terms[] = $term->name;			}		} elseif ( 'slugs' === $_fields ) {			foreach ( $term_objects as $term ) {				$_terms[] = $term->slug;			}		} elseif ( 'id=>name' === $_fields ) {			foreach ( $term_objects as $term ) {				$_terms[ $term->term_id ] = $term->name;			}		} elseif ( 'id=>slug' === $_fields ) {			foreach ( $term_objects as $term ) {				$_terms[ $term->term_id ] = $term->slug;			}		} elseif ( 'all' === $_fields || 'all_with_object_id' === $_fields ) {			$_terms = $term_objects;		} 		return $_terms;	}

History

Introduced in 6.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-term-query.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.