View from relationship, one side not displaying anything

Support MB Views View from relationship, one side not displaying anythingResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #43711
    JorgeJorge
    Participant

    I've got a relationship between two CPTs, on the Relationship UI, it's not marked as a Reciprocal relationship (left unchecked). On each post type edit page, the relationship appears and works without any issues.

    Now, I'm trying to display CPT-A 'Projects' related to CPT-B 'Awards' on each frontend post.

    Here's the view to be displayed in a Project, which is working just fine:

    {% set args = {
        'post_type': 'award',
        'nopaging': true,
        'relationship': {
            'id': 'projects-and-awards',
            'from': post.ID,
            }
        }
    %}
    {% set awards = mb.get_posts( args ) %}
    
    {% for award in awards  %}
        <p><a href="{{ award.url }}" alt="{{award.post_title}}">{{award.post_title}}</a></p>
    {% endfor %}

    And here's the view to be displayed in an Award, that's not displaying anything, as if the loop was empty (the view works, tried it by placing the {{post.id}} and some static strings):

    {% set args = {
        'post_type': 'project',
        'nopaging': true,
        'relationship': {
            'id': 'proyectos-y-premios',
            'from': post.ID,
            }
        }
    %}
    {% set projects = mb.get_posts( args ) %}
    
    {% for project in projects  %}
        <p><a href="{{ project.url }}" alt="{{project.post_title}}">{{project.post_title}}</a></p>
    {% endfor %}

    I'm not sure why on the Award post, it's not showing anything, however on the Project post it's working without any issue.

    #43715
    PeterPeter
    Moderator

    Hello,

    On the Award post, please change the relation side to to, like this

        'relationship': {
            'id': 'proyectos-y-premios',
            'to': post.ID,
         }

    that means get Project posts related to this Award post.

    #43726
    JorgeJorge
    Participant

    I don't know why I missed that from the documentation.

    Thanks, Peter! That did the trick.

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