Home Forums Add-ons Gallery Field Print image custom fields


Print image custom fields

  • Good evening, i created some custom fields for the images in the media gallery, and i need to print them with the images in my posts.
    I have only been able to print them using the image id as a custom field.

    	$immagine=  get_post_meta($post->ID, 'immagine', true);
    	$url = wp_get_attachment_url( $immagine );
    <img src="<?php echo $url; ?>" / >
    <p><?php the_field('titolo_didascalia', $immagine); ?></p>
    <p><?php the_field('formato', $immagine); ?></p>
    <p><?php the_field('autore', $immagine); ?></p>
    <p><?php the_field('latitudine', $immagine); ?></p>
    <p><?php the_field('longitudine', $immagine); ?></p>

    I’d like to know if there id a better way to do it and if the image gallery add on print custom attachent fields in the html of the website.


  • No, this is the way you need to get fields from media, by supplying the post ID (attachment ID) when calling the_field();

  • Thanks for the answer, but if i have a gallery how can i loop to get all the media custom fields? thanks

  • Looping over a gallery field is covered here You just need to use the current image ID in the loop.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.