Forums Forums Search Search Results for 'sf_current_query'

Viewing 10 results - 141 through 150 (of 318 total)
  • Author
    Search Results
  • #192423

    Trevor
    Participant
    #192218

    In reply to: Search results


    Trevor
    Participant

    Ah, I can see what you have done now. It would need for part of the blog page template to be placed in the results.php file and for the blog template instead of calling the results shortcode, to call the content.

    I can write this for you if you want:

    In blog-page.php change lines 24-29:

    <div class="page-blog page-blog-title">Recent posts</div>
      <div class="blog-posts">
    
        <?php echo do_shortcode('[searchandfilter id="463" show="results"]');?>
      </div>
    </div>

    with:

    <?php the_content(); ?>
    

    Next, in the results.php file, find lines 68 and 69:

    </a></a>
    </div>

    I believe these have errors and should be just:

    </a>
    

    At the very end of the file is a blank line, after this:

    else  ?>
    
    <?php {
    	
    }
    ?>

    Here add two closing tags:

    </div>
    </div>

    Now find lines 25 and 26 (which are blank) and paste these lines:

    <?php global $searchandfilter;
    $sf_current_query = $searchandfilter->get(463)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      $page_title = "Recent Posts"; 
    } else {
      $page_title = "Search results for: " . $sf_current_query->get_search_term();
    }?>
    <div class="page-blog page-blog-title">Recent posts</div>
      <div class="blog-posts">

    I think that will do as you want. The title must be inside the results.php for it to be affected by if there are results.

    #192127

    In reply to: Search results


    Trevor
    Participant

    The text that says Recent post is what that line I highlighted makes. In any event that lines needs to be this instead, I think (try it):

    <div class="blog-post__title"><?php the_title();?></div>

    So, you would now need to find out if the page is filtered, like this, where the last line replaces line 42:

    <?php global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      $page_title = the_title(); 
    } else {
      $page_title = "Search results for: " . $sf_current_query->get_search_term();
    }?>
    <div class="blog-post__title"><?php echo $page_title;?></div>

    Note that this only shows the text search term. If you want fields choices, taxonomy choices, it becomes more complicated, which is what that documentation page shows how to do..

    #191996

    Trevor
    Participant

    As you are using the WooCommerce method to display results, it is your theme and/or WooCommerce that controls the output of the HTML and results. If you have access to the PHP template file being used, this PHP will generally detect if a search has been made or not:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(20549)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // your template archive code to show when there is search yet
    } else {
      // your template archive code to show search results
    }
    #191321

    Trevor
    Participant

    As you are using the Shortcode results method, and our results.php template file (infinite scroll version), 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).

    #191069

    Trevor
    Participant

    Do you have this bit:

    echo $sf_current_query->get_search_term();

    #191067

    Anonymous
    Inactive

    I don’t have any other filters, and the first link/example doesn’t seem to work.

    <?php
    //grab the active query from our search form
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1445)->current_query();
    ?>

    This should grab the search term and output it on the page, right?

    #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;?>">
Viewing 10 results - 141 through 150 (of 318 total)