Closed coreyworrell closed 7 months ago
Hi @coreyworrell
Thank you for your feedback and idea.
The template loader function in question can be seen at https://github.com/WebDevStudios/wp-search-with-algolia/blob/2.7.1/includes/class-algolia-template-loader.php#L169-L177 and part of it is going to be the $settings->should_override_search_with_instantsearch()
method call.
The reason I bring this up is because that method has its own filter already https://github.com/WebDevStudios/wp-search-with-algolia/blob/2.7.1/includes/class-algolia-settings.php#L332-L336
So something like this below would already be able to be used without any modification to the plugin.
function should_override_instantsearch( $should_override ) {
if ( is_archive() ) {
return false;
}
return $should_override;
}
add_filter( 'algolia_should_override_search_with_instantsearch', __NAMESPACE__ . '\should_override_instantsearch' );
@tw2113 thanks for the quick reply. That is great. Sorry, I was in a rush and assumed that method just returned the value from the database, not realizing there was already a filter. Thank you very much for the explanation and example.
All good. Let us know if you need anything else.
Describe the bug WordPress allows the search parameter to be used on archive pages and will only search the relevant posts being shown. Example:
/custom-post-type-archive/?s=test
will show the post type archive template (unless you have asearch.php
template, but that can be corrected by a filter as well) with those custom posts filtered by the search term. The plugin (if you have the option set to override the search page with InstantSearch) will instead show theinstantsearch.php
template.To Reproduce Steps to reproduce the behavior:
?s=term
)Expected behavior The archive template would still be shown, allowing WordPress to show the archive filtered by the search term.
I think a simple, backwards-compatible solution would be to add a filter to the
Algolia_Template_Loader::template_loader()
method conditional that would allow an override: