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.

Trying to sort by a related entry’s title (or other field)

January 07, 2008 4:22pm

Subscribe [0]
  • #1 / Jan 07, 2008 4:22pm

    atealtha

    21 posts

    The EE page needs to sort a list of weblog entries by a relationship entry (multiple, actually but it doesn’t matter right now). Right now there is some sorting going on, but it looks like it’s done by the sorting of the related entry’s entry_id. I’m trying to figure out if there is a way to specify a certain field.

    So is this possible?

    Note I cannot use the related weblog and list those entries because there are certain weblog statuses which need to be filtered on this page.

  • #2 / Jan 07, 2008 4:45pm

    Lisa Wess

    20502 posts

    Thank you for your post.  In order to offer you the best support we can, could you take a moment to answer the following questions, from the Getting Help announcement.

    1. Explain your goals and what you expected to happen. Then explain what actually
    happened.

    2. Post the error message, if any, that displayed.

    3. Give a URL where the issue can be viewed.

    4. Post example code. Make sure to use the code tag (click “code” on the button bar).

    Example:

    Your codes goes here

    5. Post the EE build you are using. The build number can be found in the footer of the control panel pages.

    Thank you.

  • #3 / Jan 07, 2008 4:57pm

    atealtha

    21 posts

    Sure

    1. I have weblog books with many related author weblog entries (sometimes multiple authors per book, in separate fields). I have a page which filters out books by certain statuses and sorts by these authors (primary author is ordered first, then second, then third, etc.). Code is pasted below, and I _think_ EE only looks at the author entry id #s. I added phony authors “A A” and “Z Z” and it looks like this is the case.

    2. No error message.

    3. URL is hidden right now, sorry.

    4.

    {exp:weblog:entries weblog='book' 
                        orderby='book_written_1|book_written_2|book_written_3|book_edited' 
                        sort='asc|asc|asc|asc'
                        show_expired='yes' 
                        show_future_entries='yes' 
                        dynamic='off' 
                        sticky='off' 
                        status='Backlist|open'}
    
    HTML here
    
    {/exp:weblog:entries}

    5. Version 1.6.1 Build 20071114

  • #4 / Jan 07, 2008 5:01pm

    Lisa Wess

    20502 posts

    Ok, now, that is great, thank you for clarifying - can you also clarify a bit on what you want the end result to display as? What is your goal?

  • #5 / Jan 07, 2008 5:11pm

    atealtha

    21 posts

    Guess my writing is off. I said

    “I have a page which filters out books by certain statuses and sorts by these authors (primary author is ordered first, then second, then third, etc.).”

    I really mean to say is

    “I have a page which filters out books by certain statuses and am trying to sort by the book authors’ names (ordered by first author’s name first, then second author’s name, then third, etc.).”

  • #6 / Jan 07, 2008 5:17pm

    Lisa Wess

    20502 posts

    Ok, so I’m still confused by the problem you’re having.  orderby= should be ordering by the information you have in the custom fields you named there; that is not happening?  What do you mean by this:

    Code is pasted below, and I _think_ EE only looks at the author entry id #s

  • #7 / Jan 07, 2008 5:27pm

    atealtha

    21 posts

    I mean the orderby= is a related entry field.

    So it is sorting by the related entry’s entry_id. I want to sort by its title, or another field if possible.

  • #8 / Jan 07, 2008 5:30pm

    Lisa Wess

    20502 posts

    Oh!  I see, I missed that important clue.  So briefly, just to re-phrase, you want to sort the initial list of entries by the contents of a related field?  Have you considered using the reverse related entries tag instead?

  • #9 / Jan 07, 2008 5:39pm

    atealtha

    21 posts

    Correct.

    I have considered reverse relationships, but this is a many to many relationship. So there is a chance two authors could display the same book, which is not what I want.

  • #10 / Jan 07, 2008 5:50pm

    Lisa Wess

    20502 posts

    This is definitely a customization that I’m going to have to move to how-to; other than reverse related entries, there isn’t an out of the box way to handle this that will meet your criteria. You may need to roll out some custom queries to achieve your goal here.

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

ExpressionEngine News!

#eecms, #events, #releases