Forums Forums Search Search Results for 'sf_current_query'

Viewing 10 results - 151 through 160 (of 318 total)
  • Author
    Search Results
  • #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.

    #184592

    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).

    #182014

    Trevor
    Participant

    You would need to be using our Shortcode Display results method, and have followed the guide to customising:

    https://support.searchandfilter.com/documentation/search-filter-pro/search-results/using-a-shortcode/

    Once you have a copy of the results.php file in a search-filter sub-folder of your theme, you can edit that file, like this (leave the PHP comments at the top outside and before this code):

    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 {
      // the results.php PHP code here
    }

    Make sure you change the ID number in that snippet to the ID number of your form.

    #181946

    Trevor
    Participant

    The Custom method relies on a theme template of some sort. Are you using a theme php template, as the logic would look something like this to do as you want:

    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 {
      // the theme template PHP code here
    }

    Change the number 1024 with your form’s ID number (from the shortcode).

    This code will likely need to be used within a part the template file that actually outputs the results (around the if query … have … posts bit).

Viewing 10 results - 151 through 160 (of 318 total)