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

Viewing 10 results - 31 through 40 (of 69 total)
  • Author
    Search Results
  • #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?

    #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];
    #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>';
    #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?

    #163328

    Trevor
    Participant

    I am not sure, but a good place to start is to echo the entire query array to the screen so you can see what everything is. Like this:

    $sf_current_query = $searchandfilter->get(53)->current_query();
    echo '<pre>';
    print_r($sf_current_query->get_array());
    echo '</pre>';
    #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>';
    }
    #142055

    In reply to: Manually get results


    Trevor
    Participant

    I am not entirely certain what you are doing with this, but WordPress needs to post the query to a page, which you could then use this to grab the query array:

    $sf_current_query = $searchandfilter->get(7050)->current_query()->get_array();
    

    Where you change the ID to the form ID of your form.

Viewing 10 results - 31 through 40 (of 69 total)