Support » Plugin: Highlight Search Terms » Possible to tweak for highlights in FacetWP templates?

  • Hi! Love your plugin. It works perfectly for displaying highlights in default WP search results.

    This is a question about getting your plugin to work with another plugin, so I understand it may be outside of scope. I’m asking anyway, as I can’t seem to figure it out on my own.

    FacetWP adds faceted search functionality, and uses custom templates to display search results. The query string for the results is “/?_search_bar=term” rather than the default WP “/?s=term”

    Would you happen to have any guidance for tweaking your plugin to function with custom results templates and a different query string format?


Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author RavanH


    Hi Phil, that’s an interesting case.

    You’d have to modify the plugin file hlst.php like this. Open it in the WordPress plugin editor and find the last class method on the page. It starts with:

    private static function have_search_terms() {

    Now in there, see this part:

    // nothing? then just leave empty array
    	self::$search_terms = array();

    Place in new lines BEFORE that part the following code:

    elseif ( isset($_GET['_search_bar']) AND $search = $_GET['_search_bar'] )
    	self::$search_terms = self::split_search_terms( $search );

    Then save and test.

    It may fail miserably but it might be a start 🙂

    Thank you!!

    It didn’t work, but it IS a great start. I’ll keep pluggin’ away until the magic happens.

    Plugin Author RavanH


    The problem is I don’t know how to get the FacetWP search terms. There is an example about BuddyPress search terms in there which might be the way but you’d need to contact the FacetWP devs (or browse the code) to know how.

    Another issue might be that FacetWP loads search via ajax request, which will subsequently not be treated by the highlight script.

    If you do find out, please share 🙂

    Hey @ravanh, FacetWP author here.

    Yes, FacetWP is ajax-based. After glancing at the code, I’m guessing it’s possible via our facetwp-loaded hook, e.g.

    $(document).on('facetwp-loaded', function() {
      window.hlst_query = FWP.facets['search_bar'].split(' ');
      for (i in window.hlst_query) {
          var t = 'mark';
          $('.facetwp-template').highlight(hlst_query[i], t, 'hilite term-' + i);
          $('.facetwp-template').find('*').highlight(hlst_query[i], t, 'hilite term-' + i);

    I do wish there was a way to re-trigger highlighting programmatically, like via HLST.highlight(). Currently a lot of the JS logic is locked behind an anonymous function:

    Thank you! My attempts are still unsuccessful so far, but there’s hope!

    Plugin Author RavanH


    Hi @mgibbs189 thanks for chipping in 🙂

    Indeed I’ll have to do this as a named function to be able to run again on ‘facetwp-loaded’. Will report back when it’s ready 🙂

    Thank you so much!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Possible to tweak for highlights in FacetWP templates?’ is closed to new replies.