Store item.thumbnail.ID in array

Support MB Views Store item.thumbnail.ID in arrayResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40925
    philippe@studiocassette.com[email protected]
    Participant

    Hi,

    I would like to display an image gallery using a shortcode from my theme (=> [vc_images_carousel images="ID1,ID2,..."] => the Ids separate with commas)

    For that, I have to retrieve the IDS of my custom field image_upload.
    Unfortunately, I can't store IDs in my array medias_ids.

    I believe there is a problem when I try to store the ID of each image in my media variable.

    Can you help me please ?

    Here is my view code :

    {% if post.image_upload %}
    {% set medias_ids = [] %}

    {% for item in post.image_upload %}
    {{ item.thumbnail.ID }}

    {% set media = item.thumbnail.ID %}

    {% if media %}{% set medias_ids = medias_ids|merge([media.ID]) %}{% endif %}
    {% endfor %}

    {% endif %}

    [vc_row]
    [vc_column]

    [vc_images_carousel images="{{ medias_ids|join(',') }}"]

    [/vc_column]
    [/vc_row]

    #40936
    PeterPeter
    Moderator

    Hello,

    Because the image_upload field saves each image ID in one row so I think you can use the WordPress function get_post_meta() to get the array of image IDs for simplicity. For example:

    {% set image_upload = mb.get_post_meta( post.ID, 'image_upload_field', false ) %}
    {% set list_images = mb.join( ',', image_upload )  %}

    Please read more on the documentation
    https://docs.metabox.io/fields/image-upload/
    https://developer.wordpress.org/reference/functions/get_post_meta/

    #40940
    philippe@studiocassette.com[email protected]
    Participant

    Thx Peter but your code doesnt work.
    I will try to find another solution...

    #40942
    philippe@studiocassette.com[email protected]
    Participant

    Finally it works 😉
    I forgot a comma
    Thx a lot Peter !
    You rock !
    Oliver

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