Get Image Attachment Meta

Support General Get Image Attachment Meta

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5315
    socialitysociality
    Participant

    Hello,

    I have an image gallery meta box(image advanced) for a custom post type.

    I also have assigned some custom meta boxes for all attachments. I want to get those metas inside the loop in my single custom post type template. Cam I do that?

    I use the known snippet to get those with no result.

    $painting_residence = rwmb_meta( 'colours_attachment_current_residence', $args = array(), $painting['ID'] );

    The code inside the loop is

    
    $paintings = rwmb_meta( 'colours_gallery_images', $args = array(), get_the_ID() );
    		if ( ! empty($paintings) ) {
    			foreach ( $paintings as $painting ) {
    				$attachment_image = wp_get_attachment_url( $painting['ID'] );
    $painting_origin = rwmb_meta( 'colours_attachment_origin_area', $painting['ID'] );
    echo $painting_origin;
    }
    }
    

    Any help would be appreciated.

    #5320
    Anh TranAnh Tran
    Keymaster

    I think your code is very close to what you want. Try changing it to:

    $paintings = rwmb_meta( 'colours_gallery_images' );
    if ( ! empty($paintings) ) {
        foreach ( $paintings as $painting ) {
            $attachment_image = wp_get_attachment_url( $painting['ID'] );
            $painting_origin = rwmb_meta( 'colours_attachment_origin_area', '', $painting['ID'] );
            echo $painting_origin;
        }
    }
    #5330
    socialitysociality
    Participant

    Ok, it worked!

    Thank you.

    I' ve got one more question. I have some select meta boxes and I want to get their name as soon as the user has selected an option and not their value.

    For example, for an option such as

    'past' => esc_html__( 'Past', 'colours-of-a-journey-plugin' ),

    I want to get the 'Past' name and not the 'past' value.

    The snippet

    $painting_time = rwmb_meta( 'colours_attachment_theme_tag', '', $painting['ID'] );

    gives me the value 'past'. How do I do that?

    Thank you in advance.

    #5333
    Anh TranAnh Tran
    Keymaster

    You can use the function rwmb_the_value (accepts the same arguments as rwmb_meta. I wrote about it here (for checkbox list and radio, but works for all fields, too).

    #5338
    socialitysociality
    Participant

    It worked that too.

    Thanx!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Get Image Attachment Meta’ is closed to new replies.