0

I have a page that I want to list the entries in a channel, but I ONLY want the entry to be listed IF it has a relationship. So I am populating the filter with the following:

<h4>SHOW BY SERVICE</h4>
<ul>
    <li class="segment-1 selected-1 active"><a href="#" class="all">All</a></li>
    {exp:channel:entries 
        channel='service' 
        orderby='title' 
        sort='asc' 
        disable='categories|member_data|pagination'
    }
        <li class="segment-{count}">
            <a href="#" class="{url_title}" style="text-transform: capitalize;">{title}</a>
        </li>
    {/exp:channel:entries}
</ul>

I don't mind writing a custom query to do it, but I tried this:

SELECT DISTINCT(title) AS parent_title FROM exp_channel_titles WHERE entry_id IN ( SELECT DISTINCT(parent_id) AS parent FROM exp_relationships )

with no luck. Maybe I am over complicating things with this one. The rest of the page is under an entry loop in another channel:

{exp:channel:entries
    channel='success_story' 
    disable='categories|member_data' 
    orderby='date' 
    sort='desc'
}
    ...

The field is in the Success Stories channel as a relationship field named {services_used} which is pointing to the Service channel to relate it to the various services used.

I just need to be able to list the Service channel entries (distinctly) if they are referenced as used by a Success Story entry.

1 Answer 1

0

I was able to get what I needed using a query. I wasn't looking at the entries correctly in their relationships. I needed the children instead of the parents.

This is what I ended up with:

{exp:query sql="SELECT title, url_title FROM exp_channel_titles WHERE entry_id IN ( SELECT DISTINCT(child_id) FROM exp_relationships ) ORDER BY title"}
    <li class="segment-{count}">
        <a href="#" class="{url_title}" style="text-transform: capitalize;">{title}</a>
    </li>
{/exp:query}

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.