Repository navigation
REST API: Add the search_columns parameter to the search endpoint - #14295
dhananjaykuber wants to merge 1 commit into
Conversation
Allow a post search to be limited to specific columns, such as titles only, as the posts endpoints already allow. Backports changes from WordPress/gutenberg#84803. See #66317.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Adds a
search_columnsparameter to the/wp/v2/searchendpoint, so a post search can be limited to specific columns, for example titles only:WP_Queryhas supportedsearch_columnssince 6.2, and the posts endpoints already expose it, but the search endpoint always matches titles, content, and excerpts. Callers that only want title matches, such as the editor's link suggestions, currently have to filter the results themselves.WP_REST_Search_Controller::get_collection_params()registerssearch_columns, using the same definition as the posts endpoints. It defaults to an empty array, which keeps the current behaviour.WP_REST_Post_Search_Handler::search_items()passes it toWP_Query.Backports WordPress/gutenberg#84803.
Trac ticket: https://core.trac.wordpress.org/ticket/66317
Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Used for: Researching the relevant code, implementing the change, and writing tests. I reviewed the changes and ran the search controller tests locally.