Forums Forums Search & Filter Pro Display search criteria (words) and # of results

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Anonymous
    #249697

    Hello, how do I display the search criteria and number of results at the top of the page? For example, if someone filters by the “cards” category, I want the word “displaying: cars” to show at the top of the results (along with the number of car results). Thank you.

    Trevor
    #249703

    In the form setting, which Display Results method are you using?

    From your question, I assume that you are not using our Shortcode Display results method. If you are using some form of page builder, what you want will not currently be possible (but we hope to make it so in V3, due in a few months).

    If you are using the As and Archive, Post Type Archive or some of the methods that use the Custom method, and if you have access to a PHP template that is used in the display of the page/results, then it is, with good PHP skills, to code what you want. You would need to know what the results array variable is named if you are using a theme PHP template. It is often named $query or $wp_query, but can be anything the developer of the theme wants.

    For example, to display the number of results, code LIKE this would do that:

    Found <?php echo $query->found_posts; ?> Results

    Code LIKE this (change the ID number to be that of your form) would display the text search term, for example:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query();
    if (!$sf_current_query->get_search_term()=="") {
      echo '<div>Displaying: ' . $sf_current_query->get_search_term() . '</div>'; 
    }

    You would want these code snippets placed inside the block that is being refreshed with Ajax (the ‘Ajax Container’).

Viewing 2 posts - 1 through 2 (of 2 total)