0

I am outputting a list of categories for entries which have prices using the code below, how can I filter it to only show unique categories? Right now it is showing multiple categories with the same name.

{exp:channel:entries channel="channel_name" dynamic="off"}
{if price}
        {exp:gwcode_categories entry_id="{entry_id}" style="linear"}{if depth == 2}{cat_url_title}{/if}{/exp:gwcode_categories}
{/if}
{/exp:channel:entries}
0

Ok, found a way using Stash and unique filter.

 {exp:stash:set_list name="products" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries channel="channel_name"}
        {if price}
            {exp:gwcode_categories entry_id="{entry_id}" depth="2"}
            {stash:parent_item_title}{parent_url_title}{/stash:parent_item_title}
            {stash:item_name}{cat_name}{/stash:item_name}
            {stash:item_url}{cat_url_title}{/stash:item_url}
            {/exp:gwcode_categories}
        {/if}
    {/exp:channel:entries}
    {/exp:stash:set_list}

    <form>
        <select><option value="">Step 2. Select Option</option>
            {exp:stash:get_list name="products" unique="yes" orderby="item_name" sort="asc"}
            <option class="{parent_item_title}" value="{item_url}">{item_name}</option>
            {/exp:stash:get_list} 
        </select>
    </form>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.