Skip to content

REST API: Add search_columns support to the search endpoint - #84803

Open
dhananjaykuber wants to merge 2 commits into
WordPress:trunkfrom
dhananjaykuber:update/83372-search-columns
Open

dhananjaykuber wants to merge 2 commits into
WordPress:trunkfrom
dhananjaykuber:update/83372-search-columns

Conversation

@dhananjaykuber

@dhananjaykuber dhananjaykuber commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #83372

Adds a search_columns parameter to /wp/v2/search, so a post search can be limited to specific columns, e.g. titles only:

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

Why?

The search endpoint always matches titles, content, and excerpts. WP_Query and the posts endpoints already support search_columns, but the search endpoint doesn't.

How?

  • Registers search_columns on the endpoint via rest_endpoints, with the same definition as the posts endpoints. The empty default keeps the current behaviour.
  • Passes it to WP_Query via rest_post_search_query. Term searches are unaffected.

Core backport: WordPress/wordpress-develop#14295 (Trac #66317).

@jeryj, this doesn't change link suggestions, which currently keep content-only matches ranked below title matches. Should they use search_columns[]=post_title? Happy to add it here or in a follow-up.

Testing Instructions

  1. Run npm run wp-env-test start and create one post with "zebra" in its title and another with "zebra" only in its content.
  2. http://localhost:8889/wp-json/wp/v2/search?search=zebra&type=post returns both posts.
  3. Adding &search_columns[]=post_title returns only the title match.
  4. search_columns[]=post_name returns a rest_invalid_param error.

Automated tests: npm run test:unit:php:base -- --filter Gutenberg_REST_Search_Columns_Test

Use of AI Tools

Claude (Claude Code, Opus 5.5) helped research the code, implement the change, and write tests. I reviewed the changes and tested them locally.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dhananjaykuber <dhananjaykuber@git.wordpress.org>
Co-authored-by: jeryj <jeryj@git.wordpress.org>

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

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

This branch has not been deployed

No deployments
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.

Link suggestions: allow /wp/v2/search to match titles only via search_columns

1 participant