WP_Term_Query::populate_terms() WordPress Method

The WP_Term_Query::populate_terms() method is used to fill a given array of term objects with data from the database. This is typically used to generate an array of all available terms for a given taxonomy.

WP_Term_Query::populate_terms( Object[]|int[] $terms ) #

Creates an array of term objects from an array of term IDs.


Description

Also discards invalid term objects.


Top ↑

Parameters

$terms

(Object[]|int[])(Required)List of objects or term ids.


Top ↑

Return

(WP_Term[]) Array of WP_Term objects.


Top ↑

Source

File: wp-includes/class-wp-term-query.php

	protected function populate_terms( $terms ) {
		$term_objects = array();
		if ( ! is_array( $terms ) ) {
			return $term_objects;
		}

		foreach ( $terms as $key => $term_data ) {
			if ( is_object( $term_data ) && property_exists( $term_data, 'term_id' ) ) {
				$term = get_term( $term_data->term_id );
				if ( property_exists( $term_data, 'object_id' ) ) {
					$term->object_id = (int) $term_data->object_id;
				}
			} else {
				$term = get_term( $term_data );
			}

			if ( $term instanceof WP_Term ) {
				$term_objects[ $key ] = $term;
			}
		}

		return $term_objects;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.9.8Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.