ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Limit channel:entries results by the relationship's source channel.

October 17, 2013 10:41am

Subscribe [2]
  • #1 / Oct 17, 2013 10:41am

    Rick Lecoat

    128 posts

    I have a channel (“Reviews”) that has a relationships field. The entry choices available in this relationships fields are drawn from TWO other channels—Books and Screenplays. The User can assign a single relationship chosen from this list (so a review can be assigned either to one book, or to one screenplay, or to neither).

    So the “Reviews” entry is the parent, the “Books” and “Screenplays” entries are children.

    Now, I want to list all book reviews, excluding the screenplay reviews or those that have not been assigned to any particular project. So, I want to limit the results of a channel:entries tag (channel=reviews”) such that it only returns results that have been assigned a relationship to an entry in the Books channel.

    I can’t see a way. Is it possible?
    TIA,
    Rick

  • #2 / Oct 18, 2013 12:04pm

    travisb

    172 posts

    What about outputting the parents of book entries that are in the reviews channel? In other words, coming at it from books side of things and from there getting the related parent entries in the reviews channel. Would that work in your case?

  • #3 / Oct 18, 2013 12:15pm

    Rick Lecoat

    128 posts

    Maaaaayyyybe. Thanks. I’ll take a closer look at that, although I have a feeling that it’s one of the myriad combinations that I’ve already tried. (To be honest, trying to keep the parent-child relationships, plus the twists and turns of the template code, straight in my head throughout this back and forth looping is giving me a head ache). I’ll come back and let you know how it works out. For the time being, I’ve introduced a workaround, which is an extra field in the Reviews channel—a set of radio button to let the editor choose whether the review is for a Book, a Screen Project, or neither. That gives me a simple hook to filter on. It works… but it’s kludgier than Kludgy McBodgejob.

  • #4 / Oct 18, 2013 12:20pm

    travisb

    172 posts

    You should be able to get to the entries you want from either direction:

    reviews channel > entries
    or
    books channel > parents of book field > reviews channel > entries

    It always helps me to make a test template with almost nothing in it so that I can test getting the simple relationship output right before complicating it with additional parameters and other template code.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases