Search Results for 'current_query'

Forums › Forums › Search › Search Results for 'current_query'

Viewing 10 results – 241 through 250 (of 385 total)
  • Author
    Search Results
  • #160387

    Trevor
    Participant

    Is this what you are looking for?

    https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    There are many snippets in the forum as well. Do this search:

    https://support.searchandfilter.com/forums/search/current_query/

    And you will find quite a few useful threads.

    #159710

    Trevor
    Participant

    Hi

    Great to speak with you. Using your customised version of our results.php template file, you had excluded text searches and so needed to add a condition to check if they were being performed without using any of the other form controls, with:

    $sf_current_query->get_search_term()==""

    and

    $sf_current_query->get_search_term()==!"

    I will close this thread for now.

    #157381

    Trevor
    Participant

    You might need this for what is in the search box:

    $search_words=$sf_current_query->get_search_term();

    and then echo that. If you search our forum:

    https://support.searchandfilter.com/forums/search/sf_current_query/

    You will see many different examples of use.

    #157375

    Anonymous
    Inactive

    Hi Trevor,

    Thanks for the quick response.

    I can get it to half work… This search query should yield the response:
    “Search Results for: green Brexit, Legatum Institute, Posts”
    http://smartthinking.staging.wpengine.com/?sfid=979&_sf_s=green&_sft_category=brexit&_sfm_think_tank=Legatum%20Institute&post_types=post#a

    At least that is what I would like it to do. But currently only the category is showing.

    This is the markup:

    <?php
        global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(979)->current_query(); ?>
                        
                
        <h1 class="archive_title"><span><?php _e("Search Results for","wpbootstrap"); ?>:</span> <?php echo esc_attr(get_search_query()); ?>
                            
             <?php              
            $args = array(
                "str" 					=> '%2$s', 
                "delim" 				=> array(", ", " - "), 
                "field_delim"				=> ', ', 
                "show_all_if_empty"			=> false 
            );
            
            echo $sf_current_query->get_fields_html(
                array("_sft_category", "_sft_post_tag", "_sft_sfdc_post_type", "_sft_sfdc_think_tank"), 
                $args
            );
            ?>
            
        </h1>

    Have I done something wrong?
    Thanks,
    Alex

    #154839

    Trevor
    Participant

    Redirecting an empty search is not a feature of the pro plugin, as the plugin is far more complex.

    It IS possible to use PHP to detect if a search has been made though, 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 VC template archive code/loop here
    }
    #154736

    Anonymous
    Inactive

    Unfortunately that’s a no-go. The complete code I put in (using your good chunk there) looked like:

    <?php global $searchandfilter;
     
    $sf_current_query = $searchandfilter->get(15)->current_query()->get_array();
    echo '<strong>Filtered by:</strong>';
    
    if ( is_empty($sf_current_query ) ) {
      echo "all";
    } else {
      foreach($sf_current_query as $key) {
      echo '&nbsp; &bull; ' . $key['active_terms'][0]['name'] . ' ';
    }	
    }?>

    Am I missing something above if? Feels like that’s maybe where I’m off?
    (The page does not display anything – no sidebar, no search form, so as-is above it pretty broken – did I close off the function properly?)

    #154721

    Trevor
    Participant

    If the query is empty, the $sf_current_query array will be empty, so you can use the PHP empty() function:

    if ( empty($sf_current_query ) ) {
      echo 'Nothing here folks.';
    } else {
    ....
    }

    I would think.


    Anonymous
    Inactive

    Hello! A while back I had a question about displaying the terms that a user had chosen to filter their search by, and we’re using this:

    <?php global $searchandfilter;
     
    $sf_current_query = $searchandfilter->get(15)->current_query()->get_array();
    echo '<strong>Filtered by:</strong>';
    foreach($sf_current_query as $key) {
      echo '&nbsp; &bull; ' . $key['active_terms'][0]['name'] . ' ';
    }
    	?>

    Which works perfectly except that it’s blank when no terms have been selected, so the user sees “Filtered by:” and nothing else.

    Can I add to the php above, using an if / else combo?
    So:

    if $sf_current_query is blank {
    echo 'all';
    else foreach($sf_current_query as $key) {
      echo '&nbsp; &bull; ' . $key['active_terms'][0]['name'] . ' ';
    } ?>

    The “if” bit is where I’m lost – please help!

    #151119

    Anonymous
    Inactive

    haha yes. That makes total sense, and it’s working as expected now. I was testing the output at the top of the file without thinking about where the results refresh…

    One more thing… I would like to wrap the label and term in markup. Is there a way to return the label and term values separately?
    For instance, echo $sf_current_query->get_field_string("_sft_location"); returns “Location: Africa”, but I would like it to read <dt>Location:</dt><dd>Africa</dd>.

    Thanks!

    #147706

    In reply to: Taxonomy Breadcrumbs


    Anonymous
    Inactive

    For clarity, this is what I used:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    }
Viewing 10 results – 241 through 250 (of 385 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.