WP_REST_Terms_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error
- Since
- 4.7.0, 6.8.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php:235
Compatibility
- WordPress
- since 6.8.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$requestWP_REST_Request- Full details about the request.
Return value
WP_REST_Response|WP_Error- Response object on success, or WP_Error object on failure.
Performance profile
How much work a call to WP_REST_Terms_Controller::get_items() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 113–178
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via wp_get_object_terms().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 238.
Third-party callbacks on 'rest_{$this->taxonomy}_query' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
wp_get_object_terms()called directly
Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 24 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Terms_Controller::get_items() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && !$page | 113–137 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && !$page | 116–136 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg() |
!isset($prepared_args) && !isset($registered) && !empty($prepared_args) && !$page | 123–147 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && isset($taxonomy_obj) && !$page | 124–143 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) | 124–151 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && !empty($prepared_args) && !$page | 126–146 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && isset($taxonomy_obj) && !$page | 127–142 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) | 127–150 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && isset($taxonomy_obj) && !$page | 134–153 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg() |
!isset($prepared_args) && !isset($registered) && !empty($prepared_args) | 134–161 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && isset($taxonomy_obj) | 135–157 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && isset($taxonomy_obj) && !$page | 137–152 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg() |
12 further outcomes, up to 177 instructions
!isset($prepared_args) && !isset($registered) && !empty($prepared_args) | 137–160 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && $page | 137–162 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && isset($taxonomy_obj) | 138–156 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && $page | 140–161 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && isset($taxonomy_obj) | 145–167 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && !empty($prepared_args) && $page | 147–172 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && isset($taxonomy_obj) | 148–166 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && isset($taxonomy_obj) && $page | 148–168 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && !empty($prepared_args) && $page | 150–171 | ->get_collection_params(), get_taxonomy(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && empty($prepared_args) && isset($taxonomy_obj) && $page | 151–167 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), get_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && isset($taxonomy_obj) && $page | 158–178 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), taxonomy(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!isset($prepared_args) && !isset($registered) && isset($taxonomy_obj) && $page | 161–177 | ->get_collection_params(), get_taxonomy(), array_merge(), ->is_method(), apply_filters(), wp_get_object_terms(), wp_count_terms(), rest_ensure_response(), ceil(), ->header(), ceil(), ->header(), ->get_query_params(), rest_get_route_for_taxonomy_items(), rest_url(), urlencode_deep(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 237 | 113–178 | 29 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 238 | 113–178 | 29 | |
| 8.4 | 238 | 113–178 | 29 | |
| 8.3 | 238 | 113–178 | 29 | |
| 8.2 | 238 | 113–178 | 29 | |
| 8.1 | 238 | 113–178 | 29 | |
| 7.4 | 238 | 113–178 | 29 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while WP_REST_Terms_Controller::get_items() runs, in this order:
- apply_filters( rest_{$this->taxonomy}_query )filterline 343 (+108 into the body)
Filters get_terms() arguments when querying terms via the REST API.
Uses · 15
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_get_object_terms()Retrieves the terms associated with the given object(s), in the supplied taxonomies.
- get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
- wp_count_terms()Counts how many terms are in taxonomy.
- current_user_can()Returns whether the current user has the specified capability.
- rest_ensure_response()Ensures a REST response is a response object (for consistency).
- rest_url()Retrieves the URL to a REST endpoint.
- rest_get_route_for_taxonomy_items()Gets the REST API route for a taxonomy.
- add_query_arg()Retrieves a modified URL query string.
- urlencode_deep()Navigates through an array, object, or scalar, and encodes the values to be used in a URL.
- WP_REST_Terms_Controller::get_collection_params()Retrieves the query params for collections.
Show all 15
- WP_REST_Terms_Controller::prepare_item_for_response()Prepares a single term output for response.
- WP_REST_Terms_Controller::prepare_response_for_collection()
- WP_REST_Response::__construct()
Source code
public function get_items( $request ) { // Retrieve the list of registered collection query parameters. $registered = $this->get_collection_params(); /* * This array defines mappings between public API query parameters whose * values are accepted as-passed, and their internal WP_Query parameter * name equivalents (some are the same). Only values which are also * present in $registered will be set. */ $parameter_mappings = array( 'exclude' => 'exclude', 'include' => 'include', 'order' => 'order', 'orderby' => 'orderby', 'post' => 'post', 'hide_empty' => 'hide_empty', 'per_page' => 'number', 'search' => 'search', 'slug' => 'slug', ); $prepared_args = array( 'taxonomy' => $this->taxonomy ); /* * For each known parameter which is both registered and present in the request, * set the parameter's value on the query $prepared_args. */ foreach ( $parameter_mappings as $api_param => $wp_param ) { if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) { $prepared_args[ $wp_param ] = $request[ $api_param ]; } } if ( isset( $prepared_args['orderby'] ) && isset( $request['orderby'] ) ) { $orderby_mappings = array( 'include_slugs' => 'slug__in', ); if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { $prepared_args['orderby'] = $orderby_mappings[ $request['orderby'] ]; } } if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) { $prepared_args['offset'] = $request['offset']; } else { $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; } $taxonomy_obj = get_taxonomy( $this->taxonomy ); if ( $taxonomy_obj->hierarchical && isset( $registered['parent'], $request['parent'] ) ) { if ( 0 === $request['parent'] ) { // Only query top-level terms. $prepared_args['parent'] = 0; } else { if ( $request['parent'] ) { $prepared_args['parent'] = $request['parent']; } } } /* * When a taxonomy is registered with an 'args' array, * those params override the `$args` passed to this function. * * We only need to do this if no `post` argument is provided. * Otherwise, terms will be fetched using `wp_get_object_terms()`, * which respects the default query arguments set for the taxonomy. */ if ( empty( $prepared_args['post'] ) && isset( $taxonomy_obj->args ) && is_array( $taxonomy_obj->args ) ) { $prepared_args = array_merge( $prepared_args, $taxonomy_obj->args ); }Changelog
Introduced in 4.7.0. 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.0.4 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.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.