• Resolved mygrove

    (@mygrove)


    I am trying to get an “orderby” working between two related pods. There seem to be a number of questions on this topic but none quite explaining how to set this up.

    Using [each], how to sort/order by? is just what I want to do, but how are the two Pods set up (Books and Authors?) and what needs to go into the two templates?

    Thanks.

Viewing 14 replies - 16 through 29 (of 29 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @mygrove

    Ok, then is the meta field correct?
    You need to use the relationship field name from the bookauthor Pod.

    Also, could you also try to close the shortcode with [/pods] (just add it directly after the shortcode).
    If you are using more shortcodes on one template this is required.

    I’ve tested a similar case locally and it worked great.

    Cheers, Jory

    Thread Starter mygrove

    (@mygrove)

    The relationship field in bookauthor is related_book.

    In my page I now have:

    <ul>
    [pods name=”bookauthor” where=”related_book.ID = '{@id}'” orderby=”publication_date ASC” template=”book_li”]
    [/pods]
    <ul>

    Still blank.

    Is that what you intended? I realised we don’t have [each] ... [/each] in there at all now?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @mygrove

    Yes, no [each] loop is needed because you wanted a custom ordering. The each loop of a field always orders by the order you’ve set in the relationship field.

    Again, I reproduced this case locally and it worked perfectly so there must be something wrong with your setup somewhere, assuming:

    – This code is a template for a book Pod.
    – The relationship is to one or more bookauthor Pods.
    – The bookauthor Pod has a relationship field to the book Pod named related_book.

    If the above assumptions are correct. Could you test removing the orderby param to see if this outputs anything?

    Also, keep in mind that while {@id} will work, it’s actually incorrect. The object ID is uppercase ({@ID}).

    Cheers, Jory

    Thread Starter mygrove

    (@mygrove)

    I have changed @id to @ID and removed orderby=”publication_date ASC”

    Neither has made any difference.

    Could I ask you to post what you have for the template(s), Pods and fields, the output page configuration and your data so I can check it line by line with one that works?

    Thanks.

    • This reply was modified 3 years, 12 months ago by mygrove.
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @mygrove

    What I have tested is the following:

    – Created Pods named book and bookauthor.
    – Added rel field rel_bookauthor to the book Pod (multi select)
    – Added rel field rel_book to the author Pod (also multi select)
    – Made both fields bi-directional to each other.
    – Created some test posts in both and linked them to each other.
    – Added a template BookContent and auto-assigned it to the book Pod content (auto templates)
    – Added a template AuthorList with just the title.
    – Added the following shortcode in the BookContent template: [pods name="bookauthor" where="rel_book.ID = {@ID}" template="AuthorList"].

    This would ouput all related authors of that book.

    Cheers, Jory

    • This reply was modified 3 years, 12 months ago by Jory Hogeveen.
    • This reply was modified 3 years, 12 months ago by Jory Hogeveen.
    Thread Starter mygrove

    (@mygrove)

    OK, I have set this up. What do you put in your page format to get the output?

    Plugin Author Jory Hogeveen

    (@keraweb)

    What do you put in your page format to get the output?

    What do you mean with page format?

    Thread Starter mygrove

    (@mygrove)

    OK, how do you display the output? Presumably you need to set up a page?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @mygrove

    No, this is done with the auto-template functionality.
    See the Pod settings.

    How/where are you displaying the content at the moment? The page template does need some kind of context to the current page.

    Cheers, Jory

    Thread Starter mygrove

    (@mygrove)

    What I am trying to achieve is a page that lists the bookauthors and then under each author the books sorted by publication_date.

    So I assume I need a page with some code / shortcut that refers to the templates we have created?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Still, I do not know how/where the main template is loaded.
    Have you seen our introduction video?
    https://docs.pods.io/videos/grow-beyond-posts-pages-introduction-pods-framework/

    Cheers, Jory

    Thread Starter mygrove

    (@mygrove)

    Yes, I’ve seen the video(s).

    I can show one author with books beneath, but cannot create a working page that lists all authors with books sorted by publication_date. This was where I started.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Such a page would require a loop, this could be a shortcode, with a sub-loop for the books.

    So you would have the following “structure”.

    Shortcode (authors)
    > Template
    > Shortcode (books, like we discussed)
    > Sub-template

    The first shortcode could also be an archive page or something else. It’s just that the template used for authors requires the current author as context. If you use an archive the current post is that context. If you use a shortcode loop then each iteration has this context as well.

    Cheers, Jory

    Thread Starter mygrove

    (@mygrove)

    Thank you. Is there an example somewhere of this sort of nested templates?

Viewing 14 replies - 16 through 29 (of 29 total)
  • The topic ‘Uisng “orderby” in a template’ is closed to new replies.