• Resolved fortiernor

    (@fortiernor)


    Hi,
    I have pods custom post types “enjeu” that relate to “intervention”. I need to display interventions related to a given enjeu and order them by their “date_debut” custom field (pods date field) (desc). This is inside the single display for an enjeu.

    – intervention1 has post_title = “Fondation…” and date_debut = 2016-04-20
    – intervention2 has post_title = “Marche…” and date_debut = 2016-08-14
    I want intervention2 to show up before (above) intervention1.

    I do so from the pods single item widget (in Elementor pro).

    This template displays the interventions (out of order, i1 then i2):
    [if interventions]
    <h6>Interventions:</h6>
    <ul class=”fa-ul”>
    [each interventions]

    • {@interventions.post_thumbnail}{@post_title}
    • [/each]

      [/if]

      I can call the template directly from the widget, or using this shortcode:
      [pods template="enjeu_liste_interventions"]
      and get the same result.

      If I add the orderby arg to the shortcode:
      [pods name="enjeu" orderby="DATE(interventions.date_debut.meta_value) DESC" template="enjeu_liste_interventions"]
      The interventions are still displayed out of order (i1 then i2).

      This does not seem related to the date field, as ordering by post title does not work either, still displays i1 then i2:
      [pods name="enjeu" orderby="interventions.post_title DESC" template="enjeu_liste_interventions"]

      It does not seem related to DESC, as setting an earlier date on i2 and order ASC still displays i1 then i2 — orderby is simply ignored.

      I must have overlooked something obvious, but I can’t see it…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter fortiernor

    (@fortiernor)

    I’ve noticed another problem. If I call the template through a pods shortcode in the pods single item widget, such as explained above, then for each enjeu all interventions will be listed, even if the enjeu does not contain any. It seems the shortcode above is not “scoped” within the parent enjeu.
    Should I conclude that one should not call a pods template from a pods shortcode?

    Plugin Author Jory Hogeveen

    (@keraweb)

    [pods name="enjeu" orderby="DATE(interventions.date_debut.meta_value) DESC" template="enjeu_liste_interventions"]

    Not sure if this would work at all, I don’t think traversing is supported in the shortcode orderby and where attributes.

    I’ve noticed another problem. If I call the template through a pods shortcode in the pods single item widget, such as explained above, then for each enjeu all interventions will be listed, even if the enjeu does not contain any. It seems the shortcode above is not “scoped” within the parent enjeu.
    Should I conclude that one should not call a pods template from a pods shortcode?

    No, using the where attribute you can add parameters to filter what data to retrieve.
    https://docs.pods.io/displaying-pods/pods-shortcode/

    Cheers, Jory

    • This reply was modified 4 years, 5 months ago by Jory Hogeveen.
    Thread Starter fortiernor

    (@fortiernor)

    Thank you. I’ve found an obvious workaround for my simple problem: simply order the child entities correctly, by using the List view for the field in the admin form.
    I realize I should look into php to get a real sense of what is possible or not in wordpress and Pods (after 20 years of java programming, I should be able to understand at least the simpler stuff…). Could you suggest resources for learning, not php itself, not code reference such as Pods offers, but rather a high-level view of how it all ties in?

    Thank you again.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to use orderby in shortcode’ is closed to new replies.