"Insert Field" button and File Advanced inside of Loops

Support MB Views "Insert Field" button and File Advanced inside of LoopsResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30163
    AMXAMX
    Participant

    Hi,

    I have a post loop and using the Insert Field button is fine for simple fields but I have issues with inserting Checkboxes and File Advanced fields into the loop.

    For checkboxes, I have found a workaround:

    {{ mb.rwmb_the_value( 'myfield', '', post.ID, false ) }}

    It's probably not ideal, but it kind of works.

    But I cannot figure out how to output raw URLs of PDF files from File Advanced fields. The usual "Insert Fields" button doesn't help.

    How can I use such fields inside loops?

    I also tried:

    {{ mb.rwmb_meta( 'my_field_group_id', '', post.ID )['my_field_id'] }}

    But it doesn't display anything...

    Greetings,
    Tom

    #30175
    Long NguyenLong Nguyen
    Moderator

    Hi Tom,

    The multiple setting is always set to true for this field so it will return an array when getting the field value. You need to create a loop to iterate through array elements to get each file info. For example

    {% set my_file = mb.rwmb_meta( 'file_advanced', '', post.ID ) %}
    {% for item in my_file %}
        {{ item.url }}
        <br>
    {% endfor %}

    Get more details on the documentation https://docs.metabox.io/fields/file-advanced/#template-usage

    #30190
    AMXAMX
    Participant

    Thank you Long. The "set my_file" part was the missing piece. It works now.

    Greetings,
    Tom

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