Forums › Forums › Search & Filter Pro › Breadcrumbs Revisited – Hoping for Confirmation
- This topic has 4 replies, 2 voices, and was last updated 6 years, 10 months ago by Anonymous.
-
Anonymous(Private) January 24, 2018 at 5:18 pm #154498
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!
Anonymous(Private) January 24, 2018 at 8:57 pm #154736Unfortunately 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?) -
AuthorPosts