How to setup a filter
-
Hello,
Is it possible to configure filters on certain fields in an index directly in the plugin interface?
I have an event index and I would like past events not to appear in my search results.
Thanks
-
Hi @llrwac
Via UI alone, no, but we have WP filters via code available that can be useful.
function maybe_index_event_content( $should_index, \WP_Post $post ) {
// Already determined that the post should not be indexed. Return early.
if ( ! $should_index ) {
return $should_index;
}
// Check for if a past event here.
// End check.
// Return our determined result.
return $should_index;
}
add_filter( 'algolia_should_index_post', 'maybe_index_event_content', 10, 2 );I don’t have super specific code for you as I don’t know how you have your events set up, but this would be a good starting point for you, or someone else with coding chops.
The
$should_indexvariable is going to be boolean, true/false, and the indexing depends on what value you return. Return false to have the given event NOT indexed, return true to have it indexed.Any news or changes on this front @llrwac ?
Closing this as resolved for the moment, but if anything comes up, let us know and we’ll be notified.
Thanks.
hi, does anybody know if its possible to add filters in search results page ?
I see in the docs that the plugin uses instantsearch.js and some examples are referenced, is this possible with the plugin ? https://instantsearchjs.netlify.app/examples/js/tourism/-
This reply was modified 1 year, 7 months ago by
jorgebook1.
-
This reply was modified 1 year, 7 months ago by
jorgebook1.
You should have all of the widget types demo’d at https://www.algolia.com/doc/guides/building-search-ui/widgets/showcase/js/ available to you once you have saved your Search Page settings to use Instantsearch for its searching. However, we don’t have all of those widgets available in the template file that we use with Instantsearch. We keep that a bit minimally scaffolded for some potentially common widgets/facets that would be useful out of box.
You can see the default Instantsearch template at https://github.com/WebDevStudios/wp-search-with-algolia/blob/2.8.1/templates/instantsearch.php and all of Algolia’s documentation should apply here.
Thanks for the reply … humm, do you know which widgets and facet can we filter ?
Isee some ratio buttons in https://www.algolia.com/doc/guides/building-search-ui/widgets/showcase/js/ how do i use them 🙂 in the template file for the plugin.
Thanks again for your kind replyThe only widget I see from the showcase that has radio buttons is the numericMenu widget.
Documentation for that one can be found at https://www.algolia.com/doc/api-reference/widgets/numeric-menu/js/
Regarding facets and filtering, that all depends on how you configure your indexes. For example with the attributesForFaceting setting https://www.algolia.com/doc/api-reference/api-parameters/attributesForFaceting/
You can configure those via code if you like, and we can provide examples of how to do that, or you could go to say https://dashboard.algolia.com/apps/MY-APP-ID-HERE/explorer/configuration/wp_searchable_posts/searchable-attributes and configure via Algolia’s dashboard.
Let me dive into those links… thank you sir ! you are an unsung hero
-
This reply was modified 1 year, 7 months ago by
The topic ‘How to setup a filter’ is closed to new replies.