Filter: Exclude posts by tag / author

I’m using instantsearch in my wordpress website. The initiation is as follows:

var search = instantsearch({
appId: algolia.application_id,
apiKey: algolia.search_api_key,
indexName: algolia.indices.searchable_posts.name,
urlSync: {
mapping: {'q': 's'},
trackedParameters: ['query']
},
searchParameters: {
facetingAfterDistinct: true,
highlightPreTag: '__ais-highlight__',
highlightPostTag: '__/ais-highlight__'
}
});

I want that posts that were written by a specific author (let’s say John) won’t be included in the search results.
Also, I want that posts that has tag “noindex” will not be shown.
Thanks a lot :slight_smile:

filters accept negations, using the NOT parameter.

The solution to instantiate instantsearch.js with the correct filter depends on the version you’re using.
On v4, you can simply use the strategy described here: https://www.algolia.com/doc/guides/building-search-ui/widgets/customize-an-existing-widget/js/#filters-your-results-in-a-way-that-is-not-covered-by-any-widget .

Otherwise, you can always use an API-key based solution, where you force the filters through an API key.
Here is an example of how to do this, for Shopify, but the idea would be the same for wordpress.

1 Like