Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 191 through 200 (of 344 total)
  • Author
    Search Results
  • #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?

    #171426

    Anonymous
    Inactive

    I also tried what you wrote here:
    https://support.searchandfilter.com/forums/topic/how-do-i-hide-initial-results/page/2/
    adding

    if ( $query->have_posts() )
    {
        global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(40276)->current_query();
    	if ($sf_current_query->is_filtered()) {
    	?>

    to the results.php file but the results are now completely hidden – on the initial page load and they are not showing after the search.

    #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];
    #169225

    Anonymous
    Inactive

    I’ve done that already, if you look at the bottom code in the original post.

    So what you’re saying is that you can’t access it via $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”)); despite “post_type” being in there?

    There’s not a lot of documentation on it so it’s difficult to know exactly what is to be expected here.
    The https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/ page just has examples but doesn’t explain much.

    #169216

    Anonymous
    Inactive

    No, I’m trying to get the post_type from $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”));

    You can see it in the image under form_fields/post_type/post_types

    Why are they not formatted in $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”)); as in the other array entries?

    #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 - 191 through 200 (of 344 total)