• Resolved craftylion

    (@cjmclean)


    I’m trying to create a loop which only shows posts associated with a certain taxonomy called “Nature”.

    [each nature]
    <li> 
    {@post_title}
    <audio src="{@file._src}">{@file.src.full}</audio></li>
    [/each]
    <audio src="{@file._src}"></audio>

    However, the result ends up with a blank page. What I’m I doing wrong?

Viewing 1 replies (of 1 total)
  • Plugin Support pdclark

    (@pdclark)

    [each] would loop over posts referenced in a relationship field associated with the current post object, depending on what is being queried by the wrapping block or shortcode.

    To loop over all posts associated with taxonomy nature, assuming the association is made with the Connections tab, one would use a where query in a Pods Item List block or shortcode.

    The where query would be nature.slug IS NOT NULL to get all posts associated with any term within the taxonomy nature.

    If the post type being queried is post and the template is named Example Template, the shortcode version would be:

    [pods name="post" template="Example Template" where="nature.slug IS NOT NULL"]

    This is the same as writing the template within the shortcode or template field in the block, then not naming a specific template:

    [pods name="post" where="nature.slug IS NOT NULL"]
        {@post_title}<br/>
    [/pods]

    The general idea is that the initial query loop is initiated by the shortcode or block, then the template is called for each item found by that query. This differs from [each] in that [each] runs a sub-loop on related posts within a field on the current object in the main loop.

    If there is a field or taxonomy connection called nature on a post, [each] would loop through the associated terms, rather than posts associated with those terms.

    If there is a relationship field called nature on post relating to other posts or another post type, [each] would loop through those related posts within the field on the currently queried post.

    So to loop through posts associated with a taxonomy, one would likely use the where attribute on the main shortcode or block, rather than [each].

Viewing 1 replies (of 1 total)

The topic ‘Each Loop tag’ is closed to new replies.