Show view using related user data

Support MB Views Show view using related user data

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #32857
    jkarel@brovisuals.nl[email protected]
    Participant

    Hi,

    I like to show related user data in a view (which I add programmaticly to a woo account page).

    This is the use case:

      Kind (child) post type contains a sponsor field with a user id.
      The user needs to see a list of all kinderen (childeren) with sponsor field == user_id

    Firstly I created a relationship with user > kind:
    User to kind relationship

    Secondly I created this view:

    {% set args = {post_type: 'kind', nopaging: true, relationship: {id: 'user-to-child', from: user.ID}} %}
    {% set kinderen = mb.get_posts( args ) %}
    
    {% for post in kinderen %}
    <div class="row">
        <div class="column" id="left-kid-column">
          <div class="image"><img src="{{ post.thumbnail.thumbnail.url }}" width="{{ post.thumbnail.thumbnail.width }}" height="{{ post.thumbnail.thumbnail.height }}" alt="{{ post.thumbnail.thumbnail.alt }}"></div>
        </div>
        <div class="column" id="right-kid-column">
          <div id="child-name">{{ post.title }}</div>
          <div id="child-project"><h5>{{ post.projectnaam.title }}</h5></div>
          <div class=excerpt>{{ post.excerpt }}</div>
      </div>
    </div>
    {% endfor %}

    Somehow the view stays empty. Any idea what I'm missing here?

    #32858
    jkarel@brovisuals.nl[email protected]
    Participant

    FYI: I noticed missing quotes around the excerpt class in the view code, but after correcting this, no results yet... 😬

    #32862
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If you are using the custom query to get the posts, please follow this documentation to show the post info https://docs.metabox.io/extensions/mb-views/#custom-query.

    For example:

    {% for post in kinderen %}
    <div class="row">
        <div class="column" id="left-kid-column">
         Post thumbnail: {{ mb.get_the_post_thumbnail( post.ID, 'thumbnail' ) }}
        </div>
        <div class="column" id="right-kid-column">
          <div id="child-name">Post title: {{ post.post_title }}</div>
      </div>
    </div>
    {% endfor %}
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.