Skip to content

REST API: Add the search_columns parameter to the search endpoint - #14295

Open
dhananjaykuber wants to merge 1 commit into
WordPress:trunkfrom
dhananjaykuber:fix/search-endpoint-search-columns
Open

dhananjaykuber wants to merge 1 commit into
WordPress:trunkfrom
dhananjaykuber:fix/search-endpoint-search-columns

Conversation

@dhananjaykuber

@dhananjaykuber dhananjaykuber commented Oct 15, 2026 •

Copy link
Copy Markdown

Adds a search_columns parameter to the /wp/v2/search endpoint, so a post search can be limited to specific columns, for example titles only:

GET /wp/v2/search?search=coffee&type=post&search_columns[]=post_title

WP_Query has supported search_columns since 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() registers search_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 to WP_Query.
  • Term searches are unaffected, since they already only match names and slugs.
  • The QUnit API fixture is updated with the new parameter.

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.

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.
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dhananjaykuber.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant