Template Parts Views in Loop

Support MB Views Template Parts Views in Loop

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #35790
    ChrisChris
    Participant

    I am using Kadence and wanted to add a view to the template loop for archive. The view only sees on CPT entry on the archive page and every post shows the same content.

    I tried to move the view to take over the archive but had similar results.

    How do I tell the view to show data from current loop item? I added the view within the query loop item but it doesn’t like being added multiple times to the page b

    #35798
    Long NguyenLong Nguyen
    Moderator

    Hi Chris,

    You can use the WordPress function get_the_ID() to get the post ID in the loop, and use the helper function rwmb_meta() to get the field value based on the post ID. Remember to use the view Type: Shortcode and add the shortcode to the loop. For example:

    {% set post_id = mb.get_the_ID() %}
    PostID: {{ post_id }}
    Field value: {{ mb.rwmb_meta( 'my-field-id', '', post_id ) }}

    Please read more on the documentation
    https://docs.metabox.io/extensions/mb-views/#custom-query
    https://developer.wordpress.org/reference/functions/get_the_id/

    #35804
    ChrisChris
    Participant

    Eh, not really working. Plus, I have relational fields going. Not even the post title works, let along a custom field. Still can't iterate over the posts in the main query loop.

    https://snipboard.io/5GaTNr.jpg
    https://snipboard.io/HOwAFU.jpg

    Ideally, this would work:
    https://snipboard.io/J6u3Bw.jpg
    The Post ID works, but doesn't bring in data: https://snipboard.io/myzYJA.jpg

    #35812
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If you create a custom query (loop) in the View, you can use the helper function rwmb_meta() or click on the field name in the Insert Fields tab to get the field value. See this screenshot https://monosnap.com/file/m6icy7DSacrLey0boxiUkUIFU7kJ4I

    And please notice that the post_title is not a custom field created by Meta Box, it is a property of the Post object so you can just use post.post_title to get the post title.

    Please read more on this documentation https://docs.metabox.io/extensions/mb-views/#custom-query

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.