Custom Fields
Re-Envisioned
Support MB Views Show view using related user data

  • Creator
    Topic
  • #32857

    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #32858

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

    #32862
    Long 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 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.