Skip to content

Name the inherited query's search field s - #60

Open
roborourke wants to merge 4 commits into
mainfrom
claude/bug-validation-fixes-07a61k-issue-50
Open

Name the inherited query's search field s#60
roborourke wants to merge 4 commits into
mainfrom
claude/bug-validation-fixes-07a61k-issue-50

Conversation

@roborourke

@roborourke roborourke commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #50.

Reproduced

With a core/search block inside a core/query that inherits, on the search results template, arriving at /?s=Alpha:

<input  class="wp-block-search__input" value="" type="search" name="query-s" required />

The field renders blank although the page is showing results for "Alpha", and clearing it deletes query-s — a parameter the URL never carried — so the "new" URL equals the current one, actions.navigate() has nothing to fetch, and the results never change. Typing a term produces ?s=Alpha&query-s=Beta, where the title still reads "Search results for: Alpha". Verified on WordPress 6.8.8 and 7.0.4.

Changes

  • inc/namespace.php: render_block_search() names the field s when the query inherits, which is the first option the issue suggests and what updateURL()'s existing name === 's' case already assumes. Prefilling then works through the same sanitize_search_query_var() call, and is_search() is true at pre_get_posts time, so the post_type => any default for a search applies as intended. query-s is still transposed onto the main query, so existing links to it keep working.
  • tests/mu-plugins/register-test-content.php rewrites the theme's search results template to place a search block inside its inheriting query loop. No bundled theme ships that arrangement, and it is the only one in which these blocks see an inherited query.
  • tests/e2e/inherited-search.spec.js asserts the field is named s and prefilled from the site's term, and that clearing it navigates and widens the results.

Verification

Both new specs fail on main — the field reports name="query-s", and the clearing test times out waiting for a navigation that never happens — and pass with the fix. Full suite: 22 passed on WP 6.8.8 and 7.0.4. composer phpcs and lint-js clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Lj871x28S1DXjoVm7AB4k5


Generated by Claude Code

Open WordPress Playground Preview

An inherited query is the main query, and WordPress resolves that from its
own `s`: a term only reaches the search results template because `s` is what
routing reads. The field was named `query-s` there, so on arrival it
rendered blank rather than showing the term being searched, and clearing it
deleted a parameter the URL never carried — the "new" URL matched the
current one, the router had nothing to fetch, and the results never changed.

Name it `s` for the inherited case. `query-s` is still transposed onto the
main query, so anything already linking to it keeps working.

The test harness rewrites the theme's search template to put a search block
inside the inheriting query loop, which is the one arrangement where these
blocks see an inherited query and no bundled theme ships it.

Fixes #50

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lj871x28S1DXjoVm7AB4k5
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

Playwright — PHP 8.3 / WP latest

passed  27 passed

Details

stats  27 tests across 7 suites
duration  35.2 seconds
commit  5fc9841

@roborourke
roborourke marked this pull request as ready for review September 2, 2026 11:39
…-fixes-07a61k-issue-50

# Conflicts:
#	inc/namespace.php
github-actions Bot added a commit that referenced this pull request Sep 2, 2026
github-actions Bot added a commit that referenced this pull request Sep 2, 2026
…-fixes-07a61k-issue-50

# Conflicts:
#	tests/e2e/README.md
#	tests/mu-plugins/register-test-content.php
github-actions Bot added a commit that referenced this pull request Sep 2, 2026
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.

Clearing search does nothing on an inherited-query Search field (query-s vs s mismatch)

2 participants