Filter hook 'rest_post_search_query'

in WP Core File wp-includes/rest-api/search/class-wp-rest-post-search-handler.php at line 93

View Source

rest_post_search_query

Filter Hook
Description
Filters the query arguments for a REST API post search request. Enables adding extra arguments or setting defaults for a post search request.

Hook Information

File Location wp-includes/rest-api/search/class-wp-rest-post-search-handler.php View on GitHub
Hook Type Filter
Line Number 93

Hook Parameters

Type Name Description
array $query_args Key value array of query var to query value.
WP_REST_Request $request The request used.

Usage Examples

Basic Usage
<?php
// Hook into rest_post_search_query
add_filter('rest_post_search_query', 'my_custom_filter', 10, 2);

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

Source Code Context

wp-includes/rest-api/search/class-wp-rest-post-search-handler.php:93 - How this hook is used in WordPress core
<?php
  88  		 * @since 5.1.0
  89  		 *
  90  		 * @param array           $query_args Key value array of query var to query value.
  91  		 * @param WP_REST_Request $request    The request used.
  92  		 */
  93  		$query_args = apply_filters( 'rest_post_search_query', $query_args, $request );
  94  
  95  		$query = new WP_Query();
  96  		$posts = $query->query( $query_args );
  97  		// Querying the whole post object will warm the object cache, avoiding an extra query per result.
  98  		$found_ids = wp_list_pluck( $posts, 'ID' );

PHP Documentation

<?php
/**
		 * Filters the query arguments for a REST API post search request.
		 *
		 * Enables adding extra arguments or setting defaults for a post search request.
		 *
		 * @since 5.1.0
		 *
		 * @param array           $query_args Key value array of query var to query value.
		 * @param WP_REST_Request $request    The request used.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/rest-api/search/class-wp-rest-post-search-handler.php
Related Hooks

Related hooks will be displayed here in future updates.