REST API: Add support for searching resources by id.
This brings support for the `include` and `exclude` collection parameters to the Search Controller. This can be used to find an item by id when it's subtype is unknown. Props kadamwhite. Fixes #56546. Built from https://develop.svn.wordpress.org/trunk@54123 git-svn-id: http://core.svn.wordpress.org/trunk@53682 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8f390b309a
commit
fc4485c17f
|
@ -331,6 +331,24 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => array( $this, 'sanitize_subtypes' ),
|
||||
);
|
||||
|
||||
$query_params['exclude'] = array(
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
$query_params['include'] = array(
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
return $query_params;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,14 @@ class WP_REST_Post_Search_Handler extends WP_REST_Search_Handler {
|
|||
$query_args['s'] = $request['search'];
|
||||
}
|
||||
|
||||
if ( ! empty( $request['exclude'] ) ) {
|
||||
$query_args['post__not_in'] = $request['exclude'];
|
||||
}
|
||||
|
||||
if ( ! empty( $request['include'] ) ) {
|
||||
$query_args['post__in'] = $request['include'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the query arguments for a REST API search request.
|
||||
*
|
||||
|
|
|
@ -70,6 +70,14 @@ class WP_REST_Term_Search_Handler extends WP_REST_Search_Handler {
|
|||
$query_args['search'] = $request['search'];
|
||||
}
|
||||
|
||||
if ( ! empty( $request['exclude'] ) ) {
|
||||
$query_args['exclude'] = $request['exclude'];
|
||||
}
|
||||
|
||||
if ( ! empty( $request['include'] ) ) {
|
||||
$query_args['include'] = $request['include'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the query arguments for a REST API search request.
|
||||
*
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1-alpha-54122';
|
||||
$wp_version = '6.1-alpha-54123';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue