Categories loop not displaying categories within search results
Hi Low - I'm having some trouble getting categories to work within the search results tag pair. Within the search results, if I use {low_search_category} I correctly get the category I searched for from the form. But if I put a categories loop inside my results tag pair - even hard coding it with the category ID for the show parameter, I still get nothing returned.
Here's my form code:
{exp:low_search:form result_page="stock-parts/compare" entry_id="[]"}
Compare
{/exp:low_search:form}
And here's my results code:
{exp:low_search:results
query="{segment_3}"
disable="member_data|pagination"
collection="products"
keywords:lang="en"
keywords:inflect="yes"
limit="5"
orderby_sort="low_search_collection_name|asc"
}
{if count == "1"}
You searched within the category: ({low_search_category})
{exp:channel:categories channel="products" style="linear" show="8"}
{category_name}{/exp:channel:categories}
{/if}
{title} and other resented entries showing up fine
{/exp:low_search:results}
It's the "you searched within..." bit that's not working - at least not when I'm trying to get the category name from the categories loop. Used outside the loop, the ID returned by the low_search_category variable is correct (8) but the categories loop shows nothing.
I need to be able to get the category into my search results so that I can display different custom fields based on which category I searched. Ideally, I'll be able to turn the category ID into a category URL tile, which will then allow me to use an embed to insert completely different content based on the category returned. First thing's first - how do I get the category into my results? Desperately need your advice on this one.
Replies
Low 12 Nov 2015 20:47
I reckon the channel:categories tag isn't compatible with nesting inside a channel:entries tag, and therefore neither a low_search:results tag.
Instead, try using the {categories} variable pair, like you would with the native channel:entries tag. That var pair also accepts a show="" parameter, which should work with the {low_search_category} variable as input.