-
AuthorSearch Results
-
March 30, 2018 at 1:16 pm #169171
In reply to: Accessing Field slug on search results
TrevorParticipantHave 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>';March 20, 2018 at 10:03 am #167030In reply to: Chosen filters
AnonymousInactiveThanks 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?
March 19, 2018 at 1:29 pm #166837In reply to: Chosen filters
AnonymousInactiveThanks 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?
March 2, 2018 at 4:57 pm #163328In reply to: How to make filter label appears in the search field
TrevorParticipantI 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>';January 24, 2018 at 8:57 pm #154736In reply to: Breadcrumbs Revisited – Hoping for Confirmation
AnonymousInactiveUnfortunately 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 ' • ' . $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?)January 24, 2018 at 5:18 pm #154498Topic: Breadcrumbs Revisited – Hoping for Confirmation
in forum Search & Filter Pro
AnonymousInactiveHello! A while back I had a question about displaying the terms that a user had chosen to filter their search by, and we’re using this:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(15)->current_query()->get_array(); echo '<strong>Filtered by:</strong>'; foreach($sf_current_query as $key) { echo ' • ' . $key['active_terms'][0]['name'] . ' '; } ?>Which works perfectly except that it’s blank when no terms have been selected, so the user sees “Filtered by:” and nothing else.
Can I add to the php above, using an if / else combo?
So:if $sf_current_query is blank { echo 'all'; else foreach($sf_current_query as $key) { echo ' • ' . $key['active_terms'][0]['name'] . ' '; } ?>The “if” bit is where I’m lost – please help!
December 14, 2017 at 9:06 pm #147706In reply to: Taxonomy Breadcrumbs
AnonymousInactiveFor 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>'; }November 15, 2017 at 11:20 am #142055In reply to: Manually get results
TrevorParticipantI 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.
November 10, 2017 at 4:25 am #141086In reply to: Some Ui questions
AnonymousInactiveok, 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'; }September 15, 2017 at 8:41 am #131197In reply to: How do I get the form fieldvalues?
TrevorParticipantThe first thing then is to find what the array (data) looks like after you submit a search (with values in those two fields). Into whichever results template you are using, I need you to add this PHP code (before the loop runs), and it will print out the array of data to your screen, which you can then post back here within code ticks (the backwards quote mark that is on the key normally to the left of the main keyboard ‘1’ key, one before the code and one after it):
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(12345)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>Where I have used
12345, you need to replace that for the ID of your form. -
AuthorSearch Results
Search Results for 'current_query() get_array'
-
Search Results
-
Hello! A while back I had a question about displaying the terms that a user had chosen to filter their search by, and we’re using this:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(15)->current_query()->get_array(); echo '<strong>Filtered by:</strong>'; foreach($sf_current_query as $key) { echo ' • ' . $key['active_terms'][0]['name'] . ' '; } ?>Which works perfectly except that it’s blank when no terms have been selected, so the user sees “Filtered by:” and nothing else.
Can I add to the php above, using an if / else combo?
So:if $sf_current_query is blank { echo 'all'; else foreach($sf_current_query as $key) { echo ' • ' . $key['active_terms'][0]['name'] . ' '; } ?>The “if” bit is where I’m lost – please help!