0

I have three channels: Books, Screenplays, and Reviews. The Reviews channel includes a relationships field, where the user can assign the review to a particular book or screenplay. Thus the relationships field draws its available choices from two channels, but the relationship itself is one-to-one (ie. Allow Multiple Relations is OFF).

As I understand it, this means that I have one parent channel (Reviews) and two child channels (Books and Screenplays).

I have no problem displaying the reviews for a specific book on the book's own page (/books/view/the-book-i-wrote); I do that by accessing the {parents} tag from inside a {exp:channel:entries channel=books} tag. However, what I also want to do is have a list of general book reviews on the book index page (/books/index.php) -- NOTE: book reviews only, excluding any screenplay reviews. So I want to limit the results derived from the reviews channel to ONLY those reviews that have been assigned a relationship to an entry residing in a specific child channel. I cannot work out how to do this.

I realised that assigning a channel parameter to the {parents} tag is not the way -- it is intended to differentiate between multiple parent channels, not limit the results derived from a particular parent.

Can anyone help me untangle this? Thanks.

2
  • I'm assuming you're using the native EE relationships field?
    – Siebird
    Oct 17, 2013 at 16:22
  • Yes, that's correct. Native EE relationships, EE 2.7.2.
    – RickL
    Oct 17, 2013 at 16:24

1 Answer 1

1

You could do something like this, but # of results may vary since the filtering is done inside the entries tag:

{exp:channel:entries channel="reviews" dynamic="no" limit="10"}
    ...
    {relationship_field channel="books"}
        {relationship_field:title}
    {/relationship_field}
{/exp:channel:entries}

Update

My only other suggestion would be to add categories to the reviews channel for each type (ie. books & screenplays)

3
  • 1
    Sadly that code didn't output anything as far as I can tell. In any case, I would expect it to access the data contents of the child entry but what I'm trying to do it to call the entries of the parent channel (Reviews) in the normal way, simply filtering out one or the other of the child channels. The problem, I think, is that the parent-child relationship is not really between channel at all, but between channel entries. I found a workaround similar to your categories idea, by adding an extra 'radio buttons' field to Reviews specifying what type of review it is. It works, but it's kludgy.
    – RickL
    Oct 17, 2013 at 18:05
  • This is a tough one as channel_id's are never saved in the relationships field.
    – Siebird
    Oct 17, 2013 at 18:38
  • Yes, it's a tricky one. At the moment I can't see any simple way of doing it except by filtering on something other than the relationship itself -- a category or a custom field. (I went the custom field route because I'm not currently using categories on the site, and I didn't want to introduce them just for this one thing).
    – RickL
    Oct 17, 2013 at 19:20

Your Answer

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

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