Algolia JS custom routing issue

I’ve got an issue with custom routing. As a base code I’ve been using everything suggested here:

Unfortunately still getting plenty of issues.
I’m using it inside my custom build search for WordPress. It works but when trying to set refinements it simply doesn’t work. And I wanted to pass categories into search.

I have set in Algolia attributes for faceting

As well like searchable attributes

I can not get categories as refinement list:


Additionally to that I’m getting query error:

I’m using Instant Search v4 .js

I appreciate piece of advice.

Thank you

the error seems to happen somewhere in stateMapping, do you have the code available somewhere?

I think you are doing ...something.query, while the something can be undefined. You need to check the existence of something first

Let me put codesandbox demo for you. So someone can have a look at it.

1 Like

I have created codesandbox but for some reason it doesn’t work like on my local environment:

I’ve updated your sandbox to work with modules locally (since otherwise that threw an error), but the main error then showed up, which was in search-routing.js. In there you have a couple references to the index name instant_search, instead of your index name wp_posts_post. I’ve fixed those issues too as you can see here: jovial-villani-4qu5t - CodeSandbox

1 Like

Amazing, thank you @haroen, I’m not sure why I missed them all. I’ve been rewriting a lot for search until 3am at night and trying to figure it out based on example. Now I know what I should update.
Besides that my main search uses 2 indexes and search within them - will fix it now and let you know.

1 Like

One quick question. I’m trying to display all categories as refinements that comes from WP attribute: taxonomies.category
But it doesn’t work. The same issue is in sandbox. But if I’m trying to display categories as a part of template with {{ taxonomies.category }} it works with no issue.

hey, this is happening because you added both a menu and a refinementList on the same attribute. This isn’t supported since there’s no reasonable way to have a menu (allows just one refinement) and a refinement list (allows multiple) on the same attribute. Unfortunately we don’t have an error message in the console around this behaviour yet.

Here I show it works in your sandbox by commenting out the second refinement, but you can also change it from a refinement list to a menu: jovial-villani-4qu5t - CodeSandbox

note that I still saw some references to the example index in the routing file, like refinementList.brand. Don’t forget to change those parts to your actual refinement data before launching!

1 Like

Hi again, thank you for explanation.
I see that. I thought this would be ok as I intended to use it for two separate indexes but first trying to use refinements from different database and pull different data but now I can see my structure issue with it. Problem solved - thank you very much!

1 Like