Relationship working on Author page but not Post

Support MB Relationships Relationship working on Author page but not PostResolved

Viewing 2 posts - 16 through 17 (of 17 total)
  • Author
    Posts
  • #41662
    OlivierOlivier
    Participant

    For anyone reading this in the future, for reference here is a code that works for my use case (finally!).

    {% set post_id = mb.get_post_id() %}
    {% set author_id = mb.get_the_author_meta( 'ID' ) %}
    
    {% set args = { 
        post_type: 'licensee', 
        relationship: { 
            id: 'user-provider', 
            from: author_id 
        } 
    } %}
    
    {% set posts = mb.get_posts( args ) %}
    
    {% for post in posts %}
        <a href="{{ post.url }}">
            <div class="mb-container related-provider provider-related-to-user">
                <div class="provider-logo">
                    {% set field = attribute( post, '_thumbnail_id' ) %}
                    {% if field is defined %}
                        {% for item in field %}
                            <img src="{{ item.medium.url }}" alt="{{ item.medium.alt }}">
                        {% endfor %}
                    {% endif %}
                </div>
                <div class="provider-name">
                    <span>{{ post.title }}</span>
                </div>
            </div>
        </a>
    {% endfor %}

    Nobody here could help me apparently, but ChatGPT helped me without hesitation. Working code, awesome!

    #41663
    OlivierOlivier
    Participant

    Actually, I think the first line {% set post_id = mb.get_post_id() %} is not necessary. It works without it.

Viewing 2 posts - 16 through 17 (of 17 total)
  • You must be logged in to reply to this topic.