Forums Forums Search Search Results for 'sf_current_query searchandfilter current_query'

Viewing 10 results - 151 through 160 (of 258 total)
  • Author
    Search Results
  • #176841

    Trevor
    Participant

    Are you using our shortcode display results method? If so, edit the results.php file to use code 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).

    Make sure you are working on a copy of the results.php file in a search-filter sub-folder of your theme/child theme folder, and not the original in our plugin template folder.

    #176709

    Anonymous
    Inactive

    That didn’t work but the one from the link you provided earlier did work.

    Here’s the code:

    global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(71131)->current_query();
    
    	$args = array(
    		"str" 					=> '%2$s', 
    		"delim" 				=> array(", ", " - "), 
    		"field_delim"				=> ', ', 
    		"show_all_if_empty"			=> false 
    	);
    	
    	$result_title = $sf_current_query->get_fields_html(
    		array("_sft_ld_course_category"), 
    		$args
    	);

    Thank you for your help with this.

    #176626

    Trevor
    Participant

    As you are if you are using our shortcode display results method (and therefore our results.php template file), it needs to be edited to 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).

    Make sure you are working on a copy of the results.php file in a search-filter sub-folder of your theme/child theme folder, and not the original in our plugin template folder.


    Trevor
    Participant

    This would depend on the layout template being used for your page. That would depend on your theme or page builder/content plugin that you are using, or, if you are using our shortcode display 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).


    Trevor
    Participant

    It does indeed make sense. Here is how you would code what you want to do:

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

    #173724

    In reply to: Select Box Like Ted


    Trevor
    Participant

    Assuming that Post Type is one of the search fields, it should work in exactly the same way. If it does not, you need to print out the entire search/filter array and examine the structure, like this:

    $sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array();
    echo '<pre>';
    print_r($sf_current_query_array);
    echo '</pre>';

    Change the ID accordingly for your form.

    And then check to see if the terms you need are contained in that.

    #173537

    Anonymous
    Inactive

    Ok, turns out I was way overengineering this. The simple solution is to put he PHP block INSIDE the element that the AJAX results load into. Like this:

    <div  id="ajax-results">
    <?php
    
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(12192)->current_query();
    	echo $sf_current_query->get_fields_html(
    		array("_sft_travelmonth","_sft_destination", "_sft_activities"), 
    		$args
    	);
    ?>
    #171986

    In reply to: Display multiple terms


    Anonymous
    Inactive

    Trevor, thanks again for spending time with me today. I really appreciated it.

    Good news, I finally figured it out!

    Here’s the happy code:

    <?php 
    
    	global $searchandfilter;
    	
    	$args = array(
    		"str" 					=> '%2$s', 
    		"delim" 				=> array(", ", " - "), 
    		"field_delim"			=> ', ', 
    		"show_all_if_empty"		=> false 
    	);
     
    $sf_current_query = $searchandfilter->get(99801)->current_query()->get_array();
    $sf_current_style_query = $searchandfilter->get(99801)->current_query()->get_fields_html(array("_sft_style", "_sft_name"),$args);
    $sf_current_cuisine_query = $searchandfilter->get(99801)->current_query()->get_fields_html(array("_sft_cuisine", "_sft_name"),$args);
    	
    echo '<strong>Filters</strong>';
    
    if ( empty($sf_current_query ) ) {
      echo ' &bull; ' . "All" . "<br /><br />";
    } else {
    
      echo ' &bull; ' . $sf_current_query['_sft_category']['active_terms'][0]['name'] . ' &bull; ' . $sf_current_query['_sfm_wpcf-location-city']['active_terms'][0]['name'] . ' &bull; ' . $sf_current_style_query . ' &bull; ' . $sf_current_cuisine_query;
    	echo "<br /><br />";
    }
    ?>

    Cheers!

    #171733

    In reply to: Display multiple terms


    Anonymous
    Inactive

    Okay, good news, I’m making progress…

    This works for the array:

    <?php 
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(99801)->current_query();
    
    if ( empty($sf_current_query ) ) {
      echo '<strong>Filters</strong>' . ' &bull; ' . "All" . "<br /><br />";
    } 
      else {
        $args = array(
        "str"  => '%2$s', 
        "delim"  => array(", ", " - "), 
        "field_delim"  => ', ', 
        "show_all_if_empty"  => false 
      );
      echo '<strong>Filters</strong>' . ' &bull; ' . $sf_current_query->get_fields_html(array("_sft_cuisine", "_sft_name"), $args);
      }
    	
      echo '<br />';
    ?>

    Now I need to pull in the $key[‘active_terms’][0][‘name’] from the original code (it will display before the array).

    That will give me what I’m after…
    Filters • Florida • Caribbean, Mexican

    How do I combine it?

    #171651

    In reply to: Display multiple terms


    Trevor
    Participant

    You are correct. You need to examine the data structure of the filter array and then, where multiple values are permitted, use a loop to output them.

    You can print the filter array to screen with code like this:

    $sf_current_query = $searchandfilter->get(1446)->current_query();
    echo '<pre>';
    print_r($sf_current_query->get_array());
    echo '</pre>';

    But then it is a matter of coding it in PHP. I cannot see an example code snippet on our forum though. I would have thought it possible to replace echo with explode where you are handling an array?

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