Skip to content

Remove query-{id}-page pagination parameter while searching - #22

Closed
samikeijonen wants to merge 1 commit into
humanmade:mainfrom
samikeijonen:fix/search-on-pages
Closed

Remove query-{id}-page pagination parameter while searching#22
samikeijonen wants to merge 1 commit into
humanmade:mainfrom
samikeijonen:fix/search-on-pages

Conversation

@samikeijonen

Copy link
Copy Markdown
Contributor

Search does not work on paginated pages, therefor remove it.

This should be OK because search is expected to search from all items, not just from paged items.

Fixes #21.

Search does not work on paginated pages, therefor remove it.

This should be OK because search is expected to search from all items,
not just from paged items.

Fixes humanmade#21.

@roborourke roborourke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, I think the approach needs a small refinement but otherwise it's great. I've left some comments inline.

Comment thread build/taxonomy/render.php
Comment on lines 10 to 19

if ( $block->context['query']['inherit'] ) {
$query_var = sprintf( 'query-%s', $attributes['taxonomy'] );
$page_var = 'page';
$base_url = str_replace( '/page/' . get_query_var( 'paged' ), '', remove_query_arg( [ $query_var, $page_var ] ) );
} else {
if ( empty( $block->context['query']['inherit'] ) ) {
$query_id = $block->context['queryId'] ?? 0;
$query_var = sprintf( 'query-%d-%s', $query_id, $attributes['taxonomy'] );
$page_var = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
$base_url = remove_query_arg( [ $query_var, $page_var ] );
} else {
$query_var = sprintf( 'query-%s', $attributes['taxonomy'] );
$page_var = 'page';
$base_url = str_replace( '/page/' . get_query_var( 'paged' ), '', remove_query_arg( [ $query_var, $page_var ] ) );
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is appears to just be flipping the logic around and not actually changing anything, was it solving something specific?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roborourke Yeah, not sure what that is :)

Looks like removing pagination while doing the search should happen in view.js.

Comment thread src/taxonomy/view.js
Comment on lines +11 to +18
// Remove pagination when performing a search
// for your specific pagination format: query-{id}-page
const searchParams = url.searchParams;
[...searchParams.keys()].forEach(param => {
if (param.match(/query-\d+-page/) || param === 'paged') {
searchParams.delete(param);
}
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be possible to scope this to the current query loop block as this will reset pagination for all query loops on the page, and they should be able to work independently. E.g. if name === 's' remove the paged param, if name !== 's', remove name.replace( '-s', '-page' ).

@kadamwhite

Copy link
Copy Markdown
Contributor

@samikeijonen Are you interested in refreshing this PR?

Copy link
Copy Markdown
Collaborator

Triaging the open PRs — this one is still wanted and still fixes a real bug (#21), so thanks for it and apologies for the wait.

Could you rebase onto main when you get a chance? The branch is ~74 commits behind and, more importantly, build/ was removed from the repository in c1aabe0 — built files are now generated at release time and gitignored. Your branch still carries 5 changed files under build/taxonomy/, which is where the conflicts come from. Dropping those and keeping only the src/taxonomy/view.js change rebases cleanly; I tried it locally and there are no source conflicts.

A few review notes while you're in there:

  1. Anchor the regex. param.match( /query-\d+-page/ ) is unanchored, so it also matches anything merely containing that pattern. /^query-\d+-page$/ is what's meant.

  2. query-page is missed. render.php falls back to a page var with no ID when the block has no queryId in context:

    $page_var = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';

    \d+ won't match that, so the bug survives in that case. Something like /^query-(\d+-)?page$/ covers both.

  3. It clears pagination for every loop on the page, not just this one. The search action was deliberately scoped to the block's own context ("Scope search to block context so multiple searchable query loops may coexist"), so stripping all query-*-page params resets unrelated loops further down the page. Since updateURL() already receives the field's name, the loop ID can be derived from it and only that loop's page var removed — with paged/page handled for the inherited case.

  4. Pretty permalinks. For an inherited query, pagination can live in the path (/page/2/) rather than a query param. render.php strips that server-side when building $base_url, but updateURL() builds from the form action, so the path segment can survive. Worth stripping /page/N/ from url.pathname too.

  5. Minor: the repo follows WordPress spacing (if ( foo ), [ ...bar ]) — npm run lint:js will flag the added lines.

None of that is blocking in spirit; if you'd rather just rebase and drop the build/ files, we can take the regex and scoping refinements in a follow-up. If you'd prefer not to pick it back up, say so and we'll carry it forward from your commit with credit.


Generated by Claude Code

roborourke pushed a commit that referenced this pull request Sep 2, 2026
The search block's form action is built from the current URL, so the
pagination parameter the pagination block wrote is carried into the search.
Searching from page 2 asks for page 2 of the matches, and a term with only
one page of results renders an empty loop over results that do exist.

Remove the loop's page parameter from the action, named as core names it so
the parameter the pagination block wrote is the one that gets dropped. The
taxonomy filter already resets pagination this way.

Reported and first fixed by @samikeijonen in #22, which resets the same
parameter on the JS side.

Props samikeijonen.

Fixes #21

Co-authored-by: Sami Keijonen <1820415+samikeijonen@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lj871x28S1DXjoVm7AB4k5

Copy link
Copy Markdown
Collaborator

Thanks for this, and sorry it sat for so long — the diagnosis was right and the report in #21 was spot on.

We've gone with #59, which drops the same parameter from the search block's form action rather than in updateURL(), so a native form submit with JS disabled gets the reset too. Your commit is credited in it (props @samikeijonen), and #21 is fixed by that PR.

Closing in favour of #59. Much appreciated.


Generated by Claude Code

@roborourke roborourke closed this Sep 2, 2026
@samikeijonen

Copy link
Copy Markdown
Contributor Author

@roborourke Great to hear!

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.

Search does not work in paginated pages

3 participants