Forums Forums Search Search Results for 'sf_current_query active_terms'

Viewing 10 results - 21 through 30 (of 50 total)
  • Author
    Search Results
  • #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));
    	?>
    #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?

    #154736

    Anonymous
    Inactive

    Unfortunately that’s a no-go. The complete code I put in (using your good chunk there) looked like:

    <?php global $searchandfilter;
     
    $sf_current_query = $searchandfilter->get(15)->current_query()->get_array();
    echo '<strong>Filtered by:</strong>';
    
    if ( is_empty($sf_current_query ) ) {
      echo "all";
    } else {
      foreach($sf_current_query as $key) {
      echo '&nbsp; &bull; ' . $key['active_terms'][0]['name'] . ' ';
    }	
    }?>

    Am I missing something above if? Feels like that’s maybe where I’m off?
    (The page does not display anything – no sidebar, no search form, so as-is above it pretty broken – did I close off the function properly?)

    #147706

    In reply to: Taxonomy Breadcrumbs


    Anonymous
    Inactive

    For clarity, this is what I used:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    }
    #141086

    In reply to: Some Ui questions


    Anonymous
    Inactive

    ok, great help over skype Trevor – exactly what i was after and pretty much all sorted – thanks!

    for anyone interested

    1. use pre and print r instead of var dump to get the bits you need:

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

    2. I ended up with this in my page template to target the ACF meta name chosen in the S&F query – i also ended up trying to cope with the All values parts being sent if no specific options are selected (i hide all items selection in front end):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(7050)->current_query()->get_array();
    
    if ($sf_current_query['_sfm_comfort']['active_terms'][0]['name'] == ""){
      echo 'no preference for comfort';
    } else {
      echo '$sf_current_query['_sfm_comfort']['active_terms'][0]['name'] . ' comfort';
    }
    #140420

    In reply to: Some Ui questions


    Anonymous
    Inactive

    Hi Trevor, got a little further with styling so thanks for that. One thing with accessing the search data so I can display what’s been searched for – i’ve looked at

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

    but am not getting any output. I’m using ACF meta fields for all the search criteria so maybe I need to use something differently?

    ?_sfm_comfort=medium&_sfm_value_judgement=bestquality&_sfm_state=wa
    is the query string

    i’m using this in the custom page template:

    echo $sf_current_query->get_fields_html(
    array(“_sfm_comfort”)
    );

    echo $sf_current_query->get_field_string(“_sfm_comfort”);

    also doesn’t give any result.

    the var dump gives:
    array(3) { [“_sfm_comfort”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(6) “Medium” [“value”]=> string(6) “medium” } } } [“_sfm_value_judgement”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(12) “Best Quality” [“value”]=> string(11) “bestquality” } } } [“_sfm_state”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(2) “WA” [“value”]=> string(2) “wa” } } } }

    help appreciated – cheers
    Mike


    Anonymous
    Inactive

    Hi Trevor,

    Thanks for the reply, I found the solution:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1274)->current_query()->get_array();
    foreach($sf_current_query as $key) {
    	echo '<span>' . $key['value'] . ' ' . $key['name'] . ' ' . $key['active_terms'][0]['name'] . ', </span>'; 
    	}	
    #122756

    In reply to: Category Description


    Anonymous
    Inactive

    Yeah that works thanks.

    How do I combine the $sf_current_query,true

    with

    $currentCat = $sf_current_query['_sft_project_category']['active_terms'][0]['id'];
    
    #122324

    In reply to: Category Description


    Anonymous
    Inactive

    Okay I’ve worked out how to obtain the ID and get the description but the ID has an extra 1 at the end of the string which I’ve had to strip off.

    Can you see why it would have the extra one and how to avoid it?

    Thanks

    		<?php global $searchandfilter;
    			$sf_current_query = $searchandfilter->get(119)->current_query()->get_array();
    			$currentCat = $sf_current_query['_sft_project_category']['active_terms'][0]['id'];
    			$currentCatID = rtrim($currentCat,'1');
    			echo category_description( $currentCatID );
    		 ?>
Viewing 10 results - 21 through 30 (of 50 total)