Forums Forums Search Search Results for 'current_query() get_array'

Viewing 10 results - 21 through 30 (of 69 total)
  • Author
    Search Results
  • #223002

    Trevor
    Participant

    To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. 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

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    You could temporarily use this code in your results template to display the full filter array so that you can work out the exact array part that holds the data you want:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where the ID needs to match that of your form.

    #222869

    Trevor
    Participant

    To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. 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

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    You could use this to display the filter array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where the ID needs to match that of your form.


    Trevor
    Participant

    To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. 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

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    You could use this to display the filter array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where the ID needs to match that of your form.

    #213328

    Trevor
    Participant

    You can find more details from the filter query array.

    You may need to temporarily output the array to see how to access the term that you want.

    If you add this code to the page, it will output the entire array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>
    #198357

    Anonymous
    Inactive

    Well I might have asked wrong way 🙂

    The thing is the filter as I call it with the shortcode shows up, but if I try to filter results (e.g. I select one region in the dropdown or white a text to the search input and press submit), nothing changes – the result set of $trainers remains unchanged (unfiltered), so as the $GLOBALS[‘wp_query’]->request).

    From your first link you provided, I tried this code:

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

    and got

    array (size=10)
      'paged' => int 1
      'search_filter_id' => int 1513
      'search_filter_override' => boolean false
      'posts_per_page' => int 10
      'post_status' => 
        array (size=1)
          0 => string 'publish' (length=7)
      'meta_query' => 
        array (size=0)
          empty
      'post_type' => string 'trainer' (length=7)
      'is_search' => boolean true
      'is_archive' => boolean true
      'post__in' => 
        array (size=7)
          0 => int 1284
          1 => int 1495
          2 => int 1503
          3 => int 1504
          4 => int 1505
          5 => int 1506
          6 => int 1508

    (notice there is no sign of filtering in the array). This is my main problem.

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

    #173884

    In reply to: Select Box Like Ted


    Anonymous
    Inactive

    Thanks!

    Got it working using the links you supplied.

    $sf_current_types_query = $searchandfilter->get(299)->current_query()->get_array();
    $currentType=$sf_current_types_query['post_types']['active_terms'][0]['name'];
    if ( empty($currentType) ) {
    	echo '';
    } else {
            echo '<li>' . $sf_current_types_query['post_types']['active_terms'][0]['name'] . '<i class="fa fa-times"></i></li>';
    }
    						
    ?>
    #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.

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

Viewing 10 results - 21 through 30 (of 69 total)