Automatically open single fSelect facet dropdowns when a selection is active


// Automatically keep the fSelect facet drowndown open when a selection was made.
// Keeps the fSelect facets dropdown open on page reload when a selection is in the URL.
// Intended for pages with one fSelect facet. If you have multiple fSelect facets on the page, use this snippet:

add_action( 'wp_footer', function() {
      (function($) {

        document.addEventListener('facetwp-loaded', function() {
          const facet = 'my_fselect_facet'; // Change to your fSelect facet name
          let selected = FWP.facets[facet];
          if (selected.length) {
            $(`.facetwp-facet-${facet} .facetwp-dropdown`).nodes[0];

}, 100 );