Skip to content

Conversation

@samikeijonen
Copy link

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.
Copy link
Collaborator

@roborourke roborourke left a comment

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 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
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
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 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
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' ).

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

2 participants