Remove query-{id}-page pagination parameter while searching - #22
Remove query-{id}-page pagination parameter while searching#22samikeijonen wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
Thanks for this, I think the approach needs a small refinement but otherwise it's great. I've left some comments inline.
|
|
||
| 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 ] ) ); | ||
| } |
There was a problem hiding this comment.
This is appears to just be flipping the logic around and not actually changing anything, was it solving something specific?
There was a problem hiding this comment.
@roborourke Yeah, not sure what that is :)
Looks like removing pagination while doing the search should happen in view.js.
| // 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); | ||
| } | ||
| }); |
There was a problem hiding this comment.
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' ).
|
@samikeijonen Are you interested in refreshing this PR? |
|
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 A few review notes while you're in there:
None of that is blocking in spirit; if you'd rather just rebase and drop the Generated by Claude Code |
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
|
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 Closing in favour of #59. Much appreciated. Generated by Claude Code |
|
@roborourke Great to hear! |
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.