Custom Fields
Re-Envisioned
Support General Display image by id using image_advanced?

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 2 years, 7 months ago.

  • Creator
    Topic
  • #4462

    MD3
    Participant

    How to get image by id using image_advanced?

    I have a multiple section for selectbox and image_advanced

    then below is the output of the data:

    Array
    (
        [0] => Array
            (
                [album_color] => orange
                [album_images] => Array
                    (
                        [0] => 468
                        [1] => 469
                    )
    
            )
    
        [1] => Array
            (
                [album_color] => gray
                [album_images] => Array
                    (
                        [0] => 470
                        [1] => 469
                    )
    
            )
    
    )

    How can i display the image without looping? for example i only want to get the first image in the album orange(id is 468)

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #4475

    Anh Tran
    Keymaster

    You can use this code:

    $groups = rwmb_meta( 'group_id' );
    $first_group = !empty( $groups ) && is_array( $groups ) ? reset( $groups ) : array();
    $images = !empty( $first_group['album_images'] ) && is_array( $first_group['album_images'] ) ? $first_group['album_images'] : array();
    $first_image = !empty( $images ) && is_array( images ) ? reset( $images ) : 0;
    
    echo wp_get_attachment_image( $first_image, 'thumbnail' );

    PS: Are you using the Group extension? I see you didn’t purchase it.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.