Display multiple media files connected to a user

Support MB Views Display multiple media files connected to a userResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22208
    HenriHenri
    Participant

    Hi,

    I've extended the User with an File Advanced field in which I connect multiple Media files from the library to the user. Now I would like to show that on a page, so I thought to use MB views for that. I've added the following code:

    
    {{ user.first_name }} {{ user.last_name }}
    <ul>
    {% for post in query.posts %}
    <li>{{ user.downloaded_files }}</li>
    {% endfor %}
    </ul>
    

    The first and last name are being displayed. However, for the downloaded_files it shows 'array'. It has 2 connected files, so I understand that it is an array, but how do I need to change the code so that the files are shown? Or is this not the way to accomplish my use case?

    Kind regards, Henri

    #22210
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Because the field file_advanced always returns an array when retrieving so we have to loop through the array to get items information. Here is the sample code:

    {% for item in user.downloaded_files %}
        {{ item.title }}
    {% endfor %}

    You can also click to Insert Field > Users > Custom Fields > File Advanced, to generate the code automatically. See https://share.getcloudapp.com/OAuJEWm1.

    For more information, please follow the documentation https://docs.metabox.io/fields/file-advanced/#template-usage.

    #22217
    HenriHenri
    Participant

    Hi Long Nguyen,

    Awesome, it works like a charm now. I finally found a way to do what I want with your plugin 😊 I've tried it with Pods and with ACF in combination with Beaver Themer and it didn't work. Now I'm able to it with just Metabox. Awesome 👍🏻

    Kind regards, Henri

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