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.

Help w/ Ordering Reverse Related Entries

October 15, 2012 1:41pm

Subscribe [2]
  • #1 / Oct 15, 2012 1:41pm

    msmith29063

    75 posts

    I’ve run into some problems with the sorting of some reverse related entries. There’s just some limitations with EE and I’m looking for a quick solution. Any help you can provide will be appreciated.

    I have two channels: registrations and students. Students has a relationship field that links each entry to an entry in the registrations channel. (I need to continue to use the EE relationships field.)

    The students channel has two category groups assigned to it: grades (group #1) and instrument (group #2). Category IDs #1-6 are in the grades category.

    The following code achieves half of what I need it to do:

    {exp:channel:entries channel="registrations" entry_id="{segment_4}" dynamic="no"}
    <table>
    {reverse_related_entries channel="students"}
    {categories show="1|2"}
     <tr>
      <td><?php print $count; ?>.</td>
      <td>{title}</td>
      {embed="_includes/student_print" student_id="{entry_id}"}
     </tr>
    {/categories}
    {/reverse_related_entries}
    </table>
    <table>
    {reverse_related_entries channel="students"}
    {categories show="3|4"}
     <tr>
      <td><?php print $count; ?>.</td>
      <td>{title}</td>
      {embed="_includes/student_print" student_id="{entry_id}"}
     </tr>
    {/categories}
    {/reverse_related_entries}
    </table>
    <table>
    {reverse_related_entries channel="students"}
    {categories show="5|6"}
     <tr>
      <td><?php print $count; ?>.</td>
      <td>{title}</td>
      {embed="_includes/student_print" student_id="{entry_id}"}
     </tr>
    {/categories}
    {/reverse_related_entries}
    </table>
    {/exp:channel:entries}

    Here’s the student_print embed:

    {exp:channel:entries channel="students" entry_id="{embed:student_id}" dynamic="no"}
    <td><font size="2">{categories show_group="2"}{category_name}{/categories}</font></td>
    <td><font size="2">{categories show_group="1"}{category_name}{/categories}</font></td>
    {/exp:channel:entries}

    Now—what I need it to do is order the reverse related entries by the CUSTOM ORDER of the categories in the instruments category group (group #2). I just didn’t know how to go about doing what I’m currently doing (displaying the three tables—each displaying entries from specific categories in group #1) and putting them in the custom order of the categories in group #2.

    Again—the categories in group #2 are in a custom order and I need to display the related entries in that custom order. This is important.

    Any ideas? Do I need to use a custom query to do this? Another embed? I would really appreciate a code example—if possible. This is stretching my EE chops as it is.

    Thank so you much for your time.

  • #2 / Oct 16, 2012 1:09am

    msmith29063

    75 posts

    Any thoughts here? Could this be achieved with a query? I could really use some help. And I will gladly reimburse someone for their time on this. Thanks.

  • #3 / Oct 16, 2012 1:58pm

    Robin Sowell

    13255 posts

    Ouch.  I wouldn’t have set it up this way- looping an embed that contains a channel entry tag is a really resource intensive way to go.  I’d do it for a single entry- at which point the fact it loops is moot.

    But it sounds like now is not the time to reconsider the core structure.  To be clear?  I would reconsider.  This isn’t going to scale well.

    One option would be to write an extension that puts the category into a custom field automatically when they create/edit the entry.  Then just order by that custom field.  That’s pretty easy, aside from them possibly wondering why that field is there when they add entries.

    The other option- also a custom add-on (possibly php, but I’d lean toward an add-on)- effectively sort the data yourself, something like the old REEorder module did. 

    That’s just brainstorming, but I do believe either option would work.

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

ExpressionEngine News!

#eecms, #events, #releases