Hi Everyone,
I’m using {exp:super_search:results} to output channel entry info. First I’ll describe my goal, then show how I’m going about it.
Within the results loop, I need to check what categories have been assigned to the entry, and see if any of those categories match the categories that the logged in user is assigned to (I’m using Solspace User to assign users to multiple categories). At this point in the code, I have a pipe-delimited list of what categories the member belongs to, for example “10|12”. I need to check if the current entry belongs to either of those categories, and if it does, display the {title}. This works fine with the code below, except when the entry and the user are both assigned to more than one of the same category, in which case I get duplicate entries displayed, because the condition evaluates to true for each matching category. So I am trying to figure out how to prevent this. Here’s my code:
{exp:super_search:results}
{categories}
{if category_id == '10' OR category_id == '12'} {!-- I use an embed variable to generate this condition dynamically --}
{title}
{/if}
{/categories}
{/exp:super_search_results}So if I have an entry that has been assigned to category 10 and 12, the {title} is displayed twice.
Normally I would just hard code the appropriate categories to search in the results loop, which would prevent duplicates, but I need to allow the user to search based on other categories that will appear in the URL. That’s why I have a separate process within the results loop to ensure that, ultimately, only entries in the right “member group” categories are displayed.
Hopefully this makes sense. I can’t figure out an elegant way of preventing duplicates from being displayed. Perhaps I could write a plugin that answers this question:
Does this entry belong to any of these category_ids? (10|12).
If yes, do something,
if not, go to the next iteration of the results loopThis would avoid the looping nature of the {categories} tag. But, I’m not sure I am up to that challenge yet. Any creative ideas anyone? Or any advice on how I might achieve this with a plugin?