Filter hook 'rest_{$this->taxonomy}_query'

in WP Core File wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php at line 343

View Source

rest_{$this->taxonomy}_query

Filter Hook
Description
Filters get_terms() arguments when querying terms via the REST API. The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug. Possible hook names include: - `rest_category_query` - `rest_post_tag_query` Enables adding extra arguments or setting defaults for a terms collection request.

Hook Information

File Location wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php View on GitHub
Hook Type Filter
Line Number 343

Hook Parameters

Type Name Description
array $prepared_args Array of arguments for get_terms().
WP_REST_Request $request The REST API request.

Usage Examples

Basic Usage
<?php
// Hook into rest_{$this->taxonomy}_query
add_filter('rest_{$this->taxonomy}_query', 'my_custom_filter', 10, 2);

function my_custom_filter($prepared_args, $request) {
    // Your custom filtering logic here
    return $prepared_args;
}

Source Code Context

wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php:343 - How this hook is used in WordPress core
<?php
 338  		 * @link https://developer.wordpress.org/reference/functions/get_terms/
 339  		 *
 340  		 * @param array           $prepared_args Array of arguments for get_terms().
 341  		 * @param WP_REST_Request $request       The REST API request.
 342  		 */
 343  		$prepared_args = apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request );
 344  
 345  		if ( ! empty( $prepared_args['post'] ) ) {
 346  			$query_result = wp_get_object_terms( $prepared_args['post'], $this->taxonomy, $prepared_args );
 347  
 348  			// Used when calling wp_count_terms() below.

PHP Documentation

<?php
/**
		 * Filters get_terms() arguments when querying terms via the REST API.
		 *
		 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
		 *
		 * Possible hook names include:
		 *
		 *  - `rest_category_query`
		 *  - `rest_post_tag_query`
		 *
		 * Enables adding extra arguments or setting defaults for a terms
		 * collection request.
		 *
		 * @since 4.7.0
		 *
		 * @link https://developer.wordpress.org/reference/functions/get_terms/
		 *
		 * @param array           $prepared_args Array of arguments for get_terms().
		 * @param WP_REST_Request $request       The REST API request.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
Related Hooks

Related hooks will be displayed here in future updates.