0

I have the following setup:

  1. Each entry in a parent channel a number of related child entries from a child channel. These use a standard EE relationship field called “children”.

  2. The parent channel does not use categories.

  3. Each entry in the child channel has a category associated to it.

  4. There will be a some child entries related to a single parent entry from the same category.

Given a single parent channel entry, how do I generate a list of the categories for its related child entries without including duplicates if more than one child entry has the same category?

Here’s what I’ve tried so far, which results in duplicate entries when child entries are in the same category.

{exp:channel:entries limit="1" channel="parent_channel" disable="{sn_disable_standard}" required="Yes"} 
    {children}
        {children:categories}
            {category_name}
        {/children:categories}<br />
    {/children}
{/exp:channel:entries}

Is there a plug-in that I can use to store the results in a variable, then strip out the duplicate entries?

Or can this be done using standard EE tags? Or even the query module?

1 Answer 1

2

So there's a couple options to solve this. Which one you choose will depend on what Addons you want to use. As far as I can tell, there's no 100% native way to solve this.

The principle is to first get all of the child entry ids. You can then use the GWcode Categories plugin entry_id parameter to filter by these ids. The difference is how you get the IDs in the first place.

First option: Store ids using stash.

{exp:channel:entries limit="1" channel="parent_channel"} 
    {children}
        {exp:stash:append_value name="entry_ids" value="{entry_id}|"}
    {/children}
{/exp:channel:entries}

{exp:stash:parse process="end" priority="2"}
    {exp:gwcode_categories entry_id="{exp:stash:get name='entry_ids' backspace='1'}" parse="inward"}
        {cat_name}
    {/exp:gwcode_categories}
{/exp:stash:parse}

Note the {exp:stash:parse process="end"} this allows for the tags to be parsed later so that the entry ids loop is finished before the plugin tag is called.

Second option: Use Playa to get chid entry ids.

{exp:channel:entries limit="1" channel="parent_channel"} 
    {exp:gwcode_categories entry_id="{children:child_ids}" parse="inward"}
        {cat_name}
    {/exp:gwcode_categories}
{/exp:channel:entries}
2
  • But wouldn't that list all of the categories that could be assigned to the child channel entries? I need to list only the categories that are assigned to the child channel entries that are related to a particular parent channel entry. Oct 11, 2013 at 19:57
  • Oops. Sorry about that. I got confused in your question between child_channel and child entries. I updated my answer.
    – Kara Todd
    Oct 12, 2013 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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