Relationship doesn't work inside a for loop in MB View

Support MB Views Relationship doesn't work inside a for loop in MB View

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #36085
    info@ceescoenen.nl[email protected]
    Participant

    I have a loop that display all posts from CPT Begrippenlijst. I will display posts inside the loop from the relationship. It gives me no results. Doing the same on a single page works.

    Isn't this possible or do I make an mistake?

    {% set args = { post_type: 'begrippenlijst', posts_per_page: -1, order : 'ASC',orderby : 'title' } %}
    {% set posts = mb.get_posts( args ) %}

    {% for post in posts %}

    {% set relationship = attribute( relationships, 'term-to-module' ) %}
    {% for post in relationship.to %}
    title
    {% endfor %}

    {{ post.title }}
    {% endfor %}

    #36094
    Long NguyenLong Nguyen
    Moderator

    Hi,

    There are two variables post in a loop so it might not work. You can change the second variable post to post2, for example, and re-check this issue.

    {% for post in posts %}
    
    {% set relationship = attribute( relationships, 'term-to-module' ) %}
    {% for post2 in relationship.to %}
        title
    {% endfor %}
    
    {{ post.title }}
    {% endfor %}
    #36095
    info@ceescoenen.nl[email protected]
    Participant

    I have tried that and that doesn't work.

    #36135
    keith.mason@akcreation.co.uk[email protected]
    Participant

    Hi, I have the same issue - I can also confirm your fix of changing the 2nd post loop to 'for post2' does not work. Please see my thread here = https://support.metabox.io/topic/fields-from-related-posts-do-not-show-in-view-of-custom-post-type/

    Please can you advise how to fix this? Or is this a bug in Metabox which needs fixing?

    #36150
    Long NguyenLong Nguyen
    Moderator

    Hi Cees,

    Please refer to Keith's topic https://support.metabox.io/topic/fields-from-related-posts-do-not-show-in-view-of-custom-post-type/#post-36149
    to use another query in your current query to get related posts.

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