Search Results for 'sf_current_query get_array'

Forums › Forums › Search › Search Results for 'sf_current_query get_array'

Viewing 10 results – 51 through 60 (of 103 total)
  • Author
    Search Results
  • #186695

    Trevor
    Participant
    #181171

    Trevor
    Participant

    You could use PHP to look at the array that holds the filter arguments, and conditionally load different code in the same template. Again, that is custom coding.

    To start with, put this code on the results page in a suitable place:

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

    CHANGE THE ID NUMBER in the above code (1446) to whatever the ID of you form is.

    You will then see the array of filters used, and you can figure than how to fetch the value you need to add PHP to your template to test what the user has selected.

    #178123

    In reply to: Get Count of Filters


    Trevor
    Participant

    Please note that, as your license has expired, you will first need to renew at the (discounted) renewal price to receive support.

    Does this code show anything different?

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

    You will need to change the ID number of course. There are some threads on the forum that you can search for where other users have used this code to access the filters data.

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


    Anonymous
    Inactive

    I have a filter form that automatically submits as the user selects filter parameters, and displays loads via AJAX. That’s working fine but I can’t seem to get the search data to return the correct values when the search results update.

    I would like to output something like this:

    Travel Month: January
    Destinations: Grand Canyon, Las Vegas
    Activities: Great for Kids, Photography

    Here is my JS script:

    (function($){
    	$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
    		console.log("ajax complete");
    		$.ajax({
    		    type: "POST",
    		    url: "/wp-admin/admin-ajax.php",
    		    data: { action: 'filterParams'}
    		}).done(function( response ) {
    		    $( ".parameters" ).html( response );
    		});	 
    	});    
    })(jQuery);

    And here is the PHP script that I put in functions.php:

    function filterParams(){
        global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(12192)->current_query();
    	$args = array(
    		"str" 					=> '%1$s: %2$s', // this is the format of the string generated for each field
    		"delim" 				=> array(", ", " - "), 
    		"field_delim"			=> '<br />',
    		"show_all_if_empty"		=> true
    	);
    	
    	echo $sf_current_query->get_fields_html(
    		array("_sft_travelmonth","_sft_destination", "_sft_activities"), 
    		$args
    	);
    }
    add_action('wp_ajax_filterParams', 'filterParams');
    add_action('wp_ajax_nopriv_filterParams', 'filterParams');

    This is what is always getting returned in the AJAX call:

    Travel Months: All Travel Months
    Destinations: All Destinations
    Activities: All Activities0

    When I use:
    var_dump($sf_current_query->get_array());
    instead of:

    echo $sf_current_query->get_fields_html(
        array("_sft_travelmonth","_sft_destination", "_sft_activities"), 
        $args
    );

    It returns an empty array:
    array(0) { } 0

    I’ve confirmed that the form ID is correct.
    What am I missing here?

    #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!

    #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?

    #171604

    Anonymous
    Inactive

    I’ve been crunching through the forum, but not seeing an answer.

    – – – – – – – –

    I’m using the following code to display a list of current terms for the filtered search:

    </php
    
    global $searchandfilter;
     
    $sf_current_query = $searchandfilter->get(99801)->current_query()->get_array();
    echo '<strong>Filters</strong>';
    
    if ( empty($sf_current_query ) ) {
      echo ' &bull; ' . "All" . "<br />";
    } else {
      foreach($sf_current_query as $key) {
      echo ' &bull; ' . $key['active_terms'][0]['name'] . ' ';
    }
    }
    echo "<br /><br />";
    
    ?>

    – – – – – – –

    My filter includes dropdowns and checkboxes. For example:

    Market (dropdown)
    Florida

    Cuisines (checkboxes)
    [ ] American
    [X] Caribbean
    [ ] Italian
    [X] Mexican

    – – – – – – –

    The code works and the list displays, but it only shows one of the selected checkbox terms…

    Filters • Florida • Mexican

    Instead of…

    Filters • Florida • Caribbean • Mexican
    OR.. Filters • Florida • Caribbean, Mexican

    I suspect that an array is required, but not sure what/where/how.

    Please help this newbie out.

    Thanks!

    #169245

    Trevor
    Participant

    But I don’t access it using get_fields_html. I do it like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(934)->current_query()->get_array();
    $my_post_type = $sf_current_query[post_type][active_terms][0][value];
    #169189

    Anonymous
    Inactive

    I think I’ve sorted it thanks Trevor – sorry to mess you around!

    If anyone else needs it, the code is as follows:

     <?php
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1446)->current_query();
    
    $array_data = $sf_current_query->get_array();
    $typeOfSearch = $array_data["_sft_pwb-brand"]["active_terms"][0]["value"];
    
    echo $typeOfSearch ;
    
    ?>

    Where _sft_pwb-brand is the field you need, and 1446 is the ID of the search form.

Viewing 10 results – 51 through 60 (of 103 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.