Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 161 through 170 (of 344 total)
  • Author
    Search Results
  • #191063

    Trevor
    Participant

    Showing the word searched for is not so difficult. If you have other filters, then it becomes a little more complex, but I can give you links. The documentation page:

    https://searchandfilter.com/documentation/accessing-search-data/

    This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/

    #190680

    Trevor
    Participant

    Showing them is one thing, and quite complex, but I can give you links. Adding x’s to remove them is far more difficult. You would, in either case, have to do the coding yourself, as such custom coding is outside of our normal support. I think this feature is coming in V3, which is in development.

    This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/

    #190495

    Anonymous
    Inactive

    Perfect, that works. Thank you very much!

    For others, the answer was to add the following lines in the results.php, which adds a “not-sf-filtered” or “sf-filtered” class:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1075)->current_query();
    if (!$sf_current_query->is_filtered()) {
      $is_filtered = " not-sf-filtered";
    } else {
      $is_filtered = " sf-filtered";
    } ?>
    
    <div class="content-width<?php echo $is_filtered;?>">
    #190171

    Trevor
    Participant

    If you are using the Shortcode results method, and our results.php template file, it would look like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your template archive code/loop OR results.php code here
    }

    Change 1024 to the ID number of your form (from the form shortcode).

    #188787

    Trevor
    Participant

    Otherwise you would have to dig in and edit the template code to add a classname somewhere appropriate. You CAN use PHP to detect if a search has been made, like this (change the ID number to match your form – the get_search_term part is only needed if you have a text search field):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // code if no search made
    } else {
      // code if search made
    }
    #187728

    Trevor
    Participant

    I would need that user to log in and post the question, sorry. However, you want a no search set of results, and then a search set of results? If so, this should help you:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // your NO results code here
    } else {
      // your results code here
    }
    #186695

    Trevor
    Participant
    #185868

    Trevor
    Participant

    If you are using the Shortcode results method, and our results.php template file, it would look like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your template archive code/loop OR results.php code here
    }

    Change 1024 to the ID number of your form (from the form shortcode).

    #185844

    Trevor
    Participant

    Hi Rose. I think this code will do as you want, but note that you need to change the ID of the form used. Also note that the Post Snippet plugin does not require the use of <?php and ?>.

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ($sf_current_query->get_search_term()=="") {
      echo '<h2>No Search Term</h2>'; 
    } else {
      echo '<h2>Results for: ' . $sf_current_query->get_search_term() . '</h2>';
    }

    i hope that works. Modify the HTML and messages to suit.

    #185435

    In reply to: Showing search results


    Trevor
    Participant

    The text that starts:

    Architecten, interieurdesigners, vormgevers …

    What about the title? and the breadcrumbs?

    And you want to stay on that page? This means the display of the text needs to be conditional, and that means that you would need to output the text conditionally using PHP (the PHP needs to detect if a search has been made). The safest way to do this is to create the PHP as a shortcode and place the shortcode in to a Visual Composer (Page Builder) Text element.

    This plugin allows you to create a shortcode with PHP in it:

    https://wordpress.org/plugins/php-code-widget/

    The PHP would look something like:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(187)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your page title, breadcrumbs, text here
    }

    That is the theory of it.

Viewing 10 results - 161 through 170 (of 344 total)