Forums Forums Search Search Results for 'sf_current_query'

Viewing 10 results - 181 through 190 (of 318 total)
  • Author
    Search Results
  • #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.

    #169171

    Trevor
    Participant

    Have you output the full results array to see if what you want is in there, and where it is:

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

    Trevor
    Participant

    Are you trying to get terms from the results array? This search shows other user posts that fetch data from the array:

    https://support.searchandfilter.com/forums/search/sf_current_query+active_terms/

    #169120

    Anonymous
    Inactive

    Hi,

    Have an issue trying to extract post types via $postTypes1 = $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”));
    echo $postTypes1;

    only returns
    Access Levels: All Access Levels (ie: _sft_access_level)
    Topics: All Topics (ie: _sft_topic)

    but no post types aka Data Type.

    You can see the page results here:

    The debug structure of the query which clearly shows them here:
    Please see image link
    or
    Issue with get_fields_html

    Is this a bug with get_fields_html?

    If the Data Types are checked as filters it’s possible to retrieve them but that is different from retrieving the associated post types via get fields.

    	<?php  	
    		$postTypes1 = $sf_current_query->get_fields_html(array("_sf_s", "_sft_access_level", "post_type","_sft_topic"));
    		echo $postTypes1; 
    		//echo $sf_current_query->is_filtered();
    		$postTypesAll = $sf_current_query->get_array();
    		//var_dump($postTypesAll);
    		//print_r(array_values($postTypesAll));
    		$postTypes = array_column($postTypesAll, 'active_terms');
    		//var_dump($postTypes);
    		//print_r(array_values($postTypes));
    		$newArray = array();
    		foreach ($postTypes as $entry) {
    			$names = array_column($entry, 'name');
    		}
    		//var_dump($names);
    		//print_r(array_values($names));
    		$dataTypes = "<br>Data Types: ";
    		$breakChars = ", ";
    		//echo $dataTypes;
    		for ($i = 0; $i < count($names); $i++) {
    			$nameCompare = strcmp($names[$i], "Posts");
    			if ($nameCompare == 0) {
    				$names[$i] = 'Articles';
    			}
    			//echo $names[$i];
    			if ($i < count($names) - 1) {
    				echo $breakChars;
    			}
    		}
    		//var_dump($names);
    		//print_r(array_values($names));
    	?>
    #169025

    Trevor
    Participant

    Do you mean that if the user does not use the filters or search, then you want no results? You would need to edit your template file to add some logic in. 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 here
    }

    Change 1024 to the ID number of your form (from the form shortcode).

    #167030

    In reply to: Chosen filters


    Anonymous
    Inactive

    Thanks this code is doing the job for me:

    <?php
    
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(3301)->current_query()->get_array();
    	foreach ($sf_current_query as $key => $value) {
    
    			$type = $value['type'];
    			$valuei = $value['active_terms'][0]['value'];
    			$valuei1 = $value['active_terms'][1]['value'];
    			$name = $value['active_terms'][0]['name'];
    			$name1 = $value['active_terms'][1]['name'];
    
    			if ($key == '_sft_category') {
    				if ($name1 == NULL) {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo $name;
    					echo '</button>';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo $name;
    					echo '</button>';
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo $name1;
    					echo '</button>';
    				}
    			}
    
    			if ($key == '_sft_materiaalsoorten') {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo $name;
    					echo '</button>';
    			}
    
    			if ($key == '_sfm_prijsklasse') {
    				if ($valuei == 0) {
    					echo '';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo 'Prijsklasse: ';
    					echo $name;
    					echo ' vanaf';
    					echo '</button>';
    				}
    
    				if ($valuei1 == 50000) {
    					echo '';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo 'Prijsklasse: ';
    					echo $name1;
    					echo ' tot';
    					echo '</button>';
    				}
    			}
    
    			if ($key == '_sfm_vrije_valhoogte') {
    				if ($valuei == 0) {
    					echo '';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo 'Valhoogte: ';
    					echo $name;
    					echo ' vanaf';
    					echo '</button>';
    				}
    
    				if ($valuei1 == 300) {
    					echo '';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo 'Valhoogte: ';
    					echo $name1;
    					echo ' tot';
    					echo '</button>';
    				}
    			}
    
    			if ($key == '_sfm_beschikbare_obstakelvrije_ruimte') {
    				if ($valuei == 0) {
    					echo '';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo 'Beschikbare obstakelvrije ruimte: ';
    					echo $name;
    					echo ' vanaf';
    					echo '</button>';
    				}
    
    				if ($valuei1 == 350) {
    					echo '';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo 'Beschikbare obstakelvrije ruimte: ';
    					echo $name1;
    					echo ' tot';
    					echo '</button>';
    				}
    			}
    
    			if ($key == '_sfm_leeftijdsindicatie_van') {
    				if ($valuei == 0) {
    					echo '';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo 'Leeftijdsindicatie: vanaf ';
    					echo $name;
    					echo '</button>';
    				}
    
    				if ($valuei1 == 20) {
    					echo '';
    				} else {
    					echo '<button id="'.$key.'" class="but'.$type.'">';
    					echo 'Leeftijdsindicatie: tot ';
    					echo $name1;
    					echo '</button>';
    				}
    			}
    
    	}
    ?>

    But what now? How can I make it when somebody clicks on a button the filter turns off?

    #166837

    In reply to: Chosen filters


    Anonymous
    Inactive

    Thanks Trevor. I’m pretty new to PHP so I hope you dont mind me asking questions.

    I got this code:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(3301)->current_query()->get_array();
    foreach($sf_current_query as $key) {
    
    	$type = $key['type'];
    	$name = $key['active_terms'][0]['name'];
    	$name1 = $key['active_terms'][1]['name'];
    
    	echo '<button class="' . $type . '">';
    	echo $name;
    	if ($name1 == NULL) {
    	} else {
    		echo ' - ';
    		echo $name1;
    	}
    	echo '</button>';
    
    }

    I want the id of the button to be the array name.
    Like: <button id="_sfm_prijsklasse" class="post_meta">
    <button id="_sft_category" class="taxonomy">

    How can I do this?


    Trevor
    Participant

    Ah, I see. You have three possible output combinations.

    Try this:

    <?php global $searchandfilter;
        $sf_current_query = $searchandfilter->get(2398)->current_query();
        $searchTerm = $sf_current_query->get_search_term();
          $args = array(
          "str"           => '%2$s', 
          "delim"         => array(", ", " - "), 
          "field_delim"       => ', ', 
          "show_all_if_empty"     => false 
        );
      ?>
    
    <?php global $wp_query;
    $fields_html = $sf_current_query->get_fields_html( array("_sft_clinical-area", "_sft_program", "_sft_type"), $args);
        if (( $searchTerm <> "" ) && ( $fields_html <> "" ) ){
          $field_delim = ', ';
        } else {
          $field_delim = '';
        }
    
              echo $wp_query->found_posts; ?>
              Search Results for <?php echo $searchTerm . $field_delim . $fields_html; ?>

    Maybe?

Viewing 10 results - 181 through 190 (of 318 total)