WP_Term_Query::populate_terms( Object[]|int[] $terms ): WP_Term[]
- Since
- 4.9.8
- Source
wp-includes/class-wp-term-query.php:1123
Creates an array of term objects from an array of term IDs.
Description
Also discards invalid term objects.
Parameters
$termsObject[]|int[]- List of objects or term ids.
Return
WP_Term[]- Array of
WP_Termobjects.
Uses · 1
- get_term()Gets all term data from database by term ID.
Used by · 1
- WP_Term_Query::get_terms()Retrieves the query results.
Source
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; } if ( property_exists( $term_data, 'count' ) ) { $term->count = (int) $term_data->count; } } else { $term = get_term( $term_data ); } if ( $term instanceof WP_Term ) { $term_objects[ $key ] = $term; } } return $term_objects; }History
Introduced in 4.9.8. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.