wppaste
WordPress

WP_REST_Posts_Controller::prepare_taxonomy_limit_schema( array $query_params ): array

Since
5.7.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:3248
Prepares the collection schema for including and excluding items by terms.

Compatibility

WordPress
since 5.7.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

$query_paramsarray
Collection schema.

Return value

array
Updated schema.

Performance profile

How much work a call to WP_REST_Posts_Controller::prepare_taxonomy_limit_schema() 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
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
14–96

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 140.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Posts_Controller::prepare_taxonomy_limit_schema() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always14get_object_taxonomies(), wp_list_filter()
always95–96get_object_taxonomies(), wp_list_filter(), __(), __(), __(), __(), __(), __(), __(), __(), description(), __(), __(), description()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev14014–965
8.514014–965
8.414014–965
8.314014–965
8.214014–965
8.114014–9652 fewer instructions than PHP 7.4
7.414214–965

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.

Uses · 3

  • wp_list_filter()Filters a list of objects, based on a set of key => value arguments.
  • get_object_taxonomies()Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.
  • __()Retrieves the translation of $text.

Used by · 1

Source code

	private function prepare_taxonomy_limit_schema( array $query_params ) {		$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); 		if ( ! $taxonomies ) {			return $query_params;		} 		$query_params['tax_relation'] = array(			'description' => __( 'Limit result set based on relationship between multiple taxonomies.' ),			'type'        => 'string',			'enum'        => array( 'AND', 'OR' ),		); 		$limit_schema = array(			'type'  => array( 'object', 'array' ),			'oneOf' => array(				array(					'title'       => __( 'Term ID List' ),					'description' => __( 'Match terms with the listed IDs.' ),					'type'        => 'array',					'items'       => array(						'type' => 'integer',					),				),				array(					'title'                => __( 'Term ID Taxonomy Query' ),					'description'          => __( 'Perform an advanced term query.' ),					'type'                 => 'object',					'properties'           => array(						'terms'            => array(							'description' => __( 'Term IDs.' ),							'type'        => 'array',							'items'       => array(								'type' => 'integer',							),							'default'     => array(),						),						'include_children' => array(							'description' => __( 'Whether to include child terms in the terms limiting the result set.' ),							'type'        => 'boolean',							'default'     => false,						),					),					'additionalProperties' => false,				),			),		); 		$include_schema = array_merge(			array(				/* translators: %s: Taxonomy name. */				'description' => __( 'Limit result set to items with specific terms assigned in the %s taxonomy.' ),			),			$limit_schema		);		// 'operator' is supported only for 'include' queries.		$include_schema['oneOf'][1]['properties']['operator'] = array(			'description' => __( 'Whether items must be assigned all or any of the specified terms.' ),			'type'        => 'string',			'enum'        => array( 'AND', 'OR' ),			'default'     => 'OR',		); 		$exclude_schema = array_merge(			array(				/* translators: %s: Taxonomy name. */				'description' => __( 'Limit result set to items except those with specific terms assigned in the %s taxonomy.' ),			),			$limit_schema		); 		foreach ( $taxonomies as $taxonomy ) {			$base         = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;			$base_exclude = $base . '_exclude'; 			$query_params[ $base ]                = $include_schema;			$query_params[ $base ]['description'] = sprintf( $query_params[ $base ]['description'], $base ); 			$query_params[ $base_exclude ]                = $exclude_schema;			$query_params[ $base_exclude ]['description'] = sprintf( $query_params[ $base_exclude ]['description'], $base );

Changelog

Introduced in 5.7.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/rest-api/endpoints/class-wp-rest-posts-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.