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.

Show Most Recently Updated Entry Base on Reverse Relationship

May 29, 2012 3:58pm

Subscribe [3]
  • #1 / May 29, 2012 3:58pm

    grovberg

    50 posts

    In an attempt at clarify, I’m going to distinguish between entries in two channels as “events” and “posts.” I’m creating a site where the user will set up an event, and then create posts for that event. Each of those has its own channel—one for the events, and one for posts. The posts are attached to an event using a relationship field. Posts are only displayed (using a reverse_related_entries tag) on the event page and never linked to directly.

    What I’d like to do on the homepage is display the events based on which one was most recently updated. But by “updated” I really mean “event that last had a post related to it added to the system” since the events themselves aren’t really ever updated.

    Does that make sense? Anyone have any ideas?

    Thanks.

  • #2 / May 29, 2012 11:33pm

    Manoj Thomas

    185 posts

    Maybe I’m oversimplifying, but would something like this work? It sorts the posts by most recent and then displays the post’s related event title.

    {exp:channel:entries channel="posts" orderby="date" sort="desc"}
       {related_entries id="event_relationship_field"}
       {title}
       {/related_entries}
    {/exp:channel:entries}

     

  • #3 / May 30, 2012 8:43am

    grovberg

    50 posts

    Thanks a lot for replying. That’s very close to what I want, but shows the event title once for each post. So if I have

    Event 1
    —Post 1
    —Post 2
    —Post 3
    Event 2
    —Post 1
    —Post 2

    That code produces

    Event 1
    Event 1
    Event 1
    Event 2
    Event 2

    Any easy way to remove those duplicates?

    Thanks again for replying.

  • #4 / May 30, 2012 12:46pm

    Dan Decker

    7338 posts

    Hi grovberg,

    Your idea sounds very close to the example in the User Guide:

    {exp:channel:entries channel="performers" limit="15"}
            <h2>{title}</h2>
    <p>        {body}</p>
    
    <p>        {reverse_related_entries sort="desc" orderby="date"}<br />
                    </p><h3>{title}</h3>
    <p>                {body}<br />
            {/reverse_related_entries}</p>
    
    <p>        Submitted on: {entry_date format='%M %d, %Y'}<br />
    {/exp:channel:entries}

    That will order the reverse related entries by the date they were added, and group them by event.

    Make sense?

    Cheers,

  • #5 / Jun 06, 2012 10:05am

    grovberg

    50 posts

    Thanks for replying Dan, but that orders the event by when the event itself was added, not by when a post was added. So if you add a new post to event 2, it doesn’t move up to the top as the most recently updated event.

    I think Manoj’s solution was as close as it gets in EE natively, and I had a coworker cook up a regular expression that I could use with Low Replace to get rid of the duplicates. Seem inelegant, but it’s working. 😊

    Thanks again to both of you.

  • #6 / Jun 08, 2012 6:30pm

    Shane Eckert

    7174 posts

    Hey grovberg,

    I am glad is working now!

    If you need anything else, please just let us know by opening a new thread.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases