Forums Forums Search Search Results for 'sf_current_query'

Viewing 10 results - 231 through 240 (of 318 total)
  • Author
    Search Results
  • #103879

    Anonymous
    Inactive

    Hey!

    So the post “Customize initial results” was really helpful, however is it possible to display a random list of results where “// your holding template code here” is at?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // your holding template code here
    } else {
      // your normal template code here
    }

    Thanks!

    #103704

    Trevor
    Participant

    If you have access to the PHP template files, you can use something like this (change the ID for your form ID):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // your holding template code here
    } else {
      // your normal template code here
    }
    #102134

    Trevor
    Participant

    With the shortcode method, the URL re-write is not possible (it is possible only with The Post Type Archive/WooCommerce Display Results Method). This is a feature planed for V3 (being written now, release later in 2017).

    You can access the current query by adding code to the results.php file.

    I am unable to code this for you, but if you search the forum for this string sf_current_query, you will find some examples.

    #98807

    Anonymous
    Inactive

    Wooo, that got it. Thank you for your patience.

    For anyone else with this issue please see my code below. Probably not perfect but it works. 🙂

    // Exclude the default range values from the search as they are meaning the search returns no results
    
    function remove_default_range( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==25 && $query_args)	{
    		if((isset($query_args['meta_query']))&&(is_array($query_args['meta_query']))) {
    			global $searchandfilter;
    			$sf_current_query = $searchandfilter->get(25)->current_query()->get_array();
    			/* echo "<pre>";
    			print_r($sf_current_query);
    			echo "</pre>";*/
    
    			echo $sf_current_query['_sfm_minimum_per_round'][0]['value'];
    
    			if($sf_current_query['_sfm_minimum_per_round'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_round'][0]['value'] == '50000') {
    				unset($sf_current_query['_sfm_minimum_per_round']);
    			}
    
    			if($sf_current_query['_sfm_minimum_per_season'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_season'][0]['value'] == '1000000') {
    				unset($sf_current_query['_sfm_minimum_per_season']);
    			}
    
    		}			
    	}
    
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'remove_default_range', 20, 2 );
    #98769

    Trevor
    Participant

    It is a while since I looked at the array, but I think I did something like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(25)->current_query()->get_array();
    echo "<pre>";
    print_r($sf_current_query);
    echo "</pre>";
    #97498

    Trevor
    Participant

    This is not so easy, as it would the use of PHP around that grid, and I do not think VC can do that. This is how that is done in PHP:

    You can show them nothing (or a custom message) using this type of PHP code (change the number 1234 for the ID number of your search form and change the line echo ‘<div>Nothing to see here folks!</div>’; for whatever you want before the filter is used instead of the results – or remove for nothing at all):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->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 Grid here
    }

    As I say, I am not sure how you can do that though.

    #95975

    Anonymous
    Inactive

    I found some workaround, to display currently selected value:

    $tmp = $sf_current_query->get_array();
    echo $tmp["_sfm_character"]["active_terms"][0]["name"];
    

    But it may be a bug in get_field_string method from documentation, which is not working in my case:

    echo $sf_current_query->get_field_string("_sfm_character");

    #95973

    Anonymous
    Inactive

    Sorry for the mistake, I mean echo $sf_current_query->get_field_string("_sft_category"); with t

    I did things as in the documentation, but cant output any _sfm filters

    #95968

    Trevor
    Participant

    Do you mean echo $sf_current_query->get_field_string("_sft_category"); with a t and not an m?

    Does the guidance and examples in the documentation help?

    #92526

    Trevor
    Participant

    Whilst it will give you a LOT of data, this php will print out the array contents (put it in that code):

    echo '<pre>';
    print_r($sf_current_query);
    echo '</pre>';
Viewing 10 results - 231 through 240 (of 318 total)