All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Display Category Name in Search Results

gtowle 9 Sep 2015 18:50 question, complete

I have a form that searches for either keywords, tags, or categories (or a combination). I have the search results page setup to display "Searched for [keyword]" but I'm trying, unsuccessfully, to figure out how to display the category and/or tag that was searched for.

I tried using the param tag but even when I set as="category_name" and the variable as {category_name} I still get the cat_id.

The query is currently encoded.

Thank you.

Replies

  1. Low 9 Sep 2015 19:07

    The Categories filter needs category IDs as input, and will therefore always output the selected category IDs, too.

    To output the names, you can use the var as input for the native channel:categories tag, for example:

    {exp:channel:categories category_id="{low_search_category}"} 
    {category_name}
    {/exp:channel:categories}


    This should be placed inside a Form, Filters or Results tag.

  2. gtowle 9 Sep 2015 19:39

    That's helpful. I think what I'm struggling with, more specifically, is how to display the search parameters that were submitted, whether that was a keyword, category, tag, or a variation.

    Below is my search form code (sorry, I still don't know how to paste code in GS).


    On the search results template, I have this code which displays the keyword just fine. I'm trying to achieve that same result with categories and tags.

    {if low_search_keywords}Searched for {low_search_keywords}.{/if} 


    Thank you for your help.

  3. Low 9 Sep 2015 20:24

    Well, my previous answer is exactly how you display the category names that were submitted. By using the exact same code you're using to generate the options in the Form, but limiting the categories to category_id="{low_search_category}".

    You can use the same approach for the tags.

  4. gtowle 9 Sep 2015 20:40

    OK, I'll keep trying. When I first tested your code, it returned all of the categories.

    Thank you.

  5. Low 9 Sep 2015 20:42

    Did you place the code inside the Results tag? You can also place it inside a {if low_search_category}{/if} conditional.

  6. gtowle 9 Sep 2015 20:45

    Yes, I have it inside the results tag:

  7. Low 9 Sep 2015 20:46

    Oh, sorry, the param is called show="", not category_id="": https://ellislab.com/expressionengine...

  8. gtowle 9 Sep 2015 20:48

    Voilá! Thank you. I'll give it a shot with tags.

  9. Noor Mohammad 19 Nov 2016 04:32

    Since low search results tag is nothing but a channel entries tag, you might want to use something like this.

    {exp:low_search:results
    all your parameters
    }
    {if low_search_category}{categories show="{low_search_category}"}{category_name}{/categories}{/if}
    {/exp:low_search:results}


    Hope it helps!