mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Query: Add a search_columns argument to control which fields are searched in a search query.
Previously, the `s` argument of the `WP_Query::parse_query()` method searched the `post_title`, `post_excerpt`, and `post_content` fields, with no way of controlling this apart from using the `posts_search` filter and adjusting the SQL manually. This changeset adds the ability to specify which fields are searched when performing a query, using the `search_columns` argument. Props johnbillion, birgire, petitphp, audrasjb, costdev, mukesh27. Fixes #43867. git-svn-id: https://develop.svn.wordpress.org/trunk@55248 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -249,6 +249,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
'parent' => 'post_parent__in',
|
||||
'parent_exclude' => 'post_parent__not_in',
|
||||
'search' => 's',
|
||||
'search_columns' => 'search_columns',
|
||||
'slug' => 'post_name__in',
|
||||
'status' => 'post_status',
|
||||
);
|
||||
@@ -2891,6 +2892,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
);
|
||||
}
|
||||
|
||||
$query_params['search_columns'] = array(
|
||||
'default' => array(),
|
||||
'description' => __( 'Array of column names to be searched.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'enum' => array( 'post_title', 'post_content', 'post_excerpt' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
|
||||
$query_params['slug'] = array(
|
||||
'description' => __( 'Limit result set to posts with one or more specific slugs.' ),
|
||||
'type' => 'array',
|
||||
|
||||
Reference in New Issue
Block a user