Forums Forums Search & Filter Pro Chosen filters

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #166552

    Is it possible to make something like this:
    https://imgur.com/a/12vDr

    I would like some help if it’s possible.

    Thanks!

    Trevor
    #166804

    With some custom coding, it is partly possible, but it is not easy, and so not included in our support. We plan to make it a feature of V3 (in development).

    This documentation may be what you are looking for (note, if you are using Ajax to refresh the page, any such output of the query needs to be inside the Ajax container):

    https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    There are many snippets also on this forum. Try this search:

    https://support.searchandfilter.com/forums/search/current_query/

    You need to fetch the values from the taxonomy form fields. Be aware that some search terms will be held as arrays, and not single strings/values.

    Anonymous
    #166837

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

    This post has the code to show what the current query array looks like, and that will help you grab the correct bits. Try it when you have a query that contains many filters to test the code:

    https://support.searchandfilter.com/forums/topic/how-to-make-filter-label-appears-in-the-search-field/#post-163328

    Anonymous
    #167030

    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?

    Trevor
    #167074

    You would probably need some javascript to run to change the form values to remove that term, by passing from the button the term name into the javascript. How to do that I do not know.

Viewing 6 posts - 1 through 6 (of 6 total)