I am relatively new to the WordPress CMS and decided to use Pods for my custom field implementations including several image fields. While I love the admin UI I was a bit flustered trying output the images in my post template file.
After a lot of research and experimenting I wanted to share the technique I used. Obviously if there is a better way I’d love to know.
The first thing I learned from the Pods forum was that Pods saves images to the database as ‘Attachment’ posts. So, they can be accessed as you would access any regular old WordPress attachment.
Attachments have a parent-child relationship with their post which means you can programmatically grab all the attachments for a given post using this snippet adapted from WP beginners:
But this solution is sub-optimal because the parent-child relationship between the post and the image can only be broken if the image is deleted from the media library. So:
That said, I have found the best option for outputting Pod based image data by field is to combine the ‘get_post_meta’ function outlined here on the WordPress support forums with the ‘wp_get_attachment_image’ function as shown below.
The former function gives you an object with only the current images. The latter renders those images with size and alt info limited to the attachments system.