Creating a hierarchical menu with non-hierarchical taxonomies

I have 4 separate location taxonomies in WordPress:

taxonomies.location_region
taxonomies.location_country
taxonomies.location_state
taxonomies.location_city

How would I create a hierarchical facet to replicate a hierarchical taxonomy such as [‘taxonomies.location.lvl0’ , ‘taxonomies.location.lvl1’] when the taxonomy is only related by the post the taxonomy belongs to?

Here is the code which displays the facet and filters by the top level (taxonomies.location_region) ok but breaks when selecting the second level (taxonomies.location_country).

search.addWidget(
   instantsearch.widgets.hierarchicalMenu({
      container: '#facet-job-locations',
                           separator: ' > ',
                           attributes: 
 ['taxonomies.location_region','taxonomies.location_country','taxonomies.location_state','taxonomies.location_city'],
                           templates: {
                                header: '<div class="panel-heading"><h3 class="panel-title">LOCATION <span class="glyphicon glyphicon-menu-up pull-right" aria-hidden="true"></span></h3></div>'
                            },
                            cssClasses: {
                                body: 'panel-body',
                                count: 'pull-right'
                            },
                            collapsible: { collapsed: false },                 
                        })
                    );
1 Like

@bcorke Since you identified that something is clearly not working, could you replicate it inside a simple jsFiddle so we can work on that? Here’s a simple example to get you started: https://jsfiddle.net/vvoyer/0wm3donb/4/

Hello, did this get resolved? I have the same problem: I do get the list of results by top lvl filtering, but get no results found once I click on second lvl filter.

1 Like