Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Breadcrumbs Revisited – Hoping for Confirmation

Viewing 5 posts - 1 through 5 (of 5 total)
  • Kathy Webber
    #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 '&nbsp; &bull; ' . $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 '&nbsp; &bull; ' . $key['active_terms'][0]['name'] . ' ';
    } ?>

    The “if” bit is where I’m lost – please help!

    Trevor Moderator
    #154721

    If the query is empty, the $sf_current_query array will be empty, so you can use the PHP empty() function:

    if ( empty($sf_current_query ) ) {
      echo 'Nothing here folks.';
    } else {
    ....
    }

    I would think.

    Kathy Webber
    #154736

    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?)

    Trevor Moderator
    #154773

    My bad. It was late when I wrote that.

    The function is just empty() not is_empty()

    Kathy Webber
    #154866

    Perfect, thank you!

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

The topic ‘Breadcrumbs Revisited – Hoping for Confirmation’ is closed to new replies.