Home › Forums › General Issues › get_post_meta doesn't work with images › Reply To: get_post_meta doesn't work with images
ACF fields work using standard WP functions for get_post_meta() and get_option(). The functions in ACF are only wrappers for these functions.
The problem is that if you use them on a field and you don’t use the ACF functions that the values will not be formatted for you.
For example, when you create an image field and set it to return a URL. ACF does not (and never has) stored the URL of the image in the field. ACF stores the attachment ID of the image. get_post_meta() is not a theme specific function, it is a WP core function and is always available.
In order to get the URL when using get_post_meta() you need to do the work of getting the URL field yourself.
$image_id = intval(get_post_meta('image_field'));
if ($image_id) {
$image = wp_get_attachment_image_src($image_id, 'medium');
if ($image) {
?><img src="<?php echo $image[0]; ?> /><?php
}
}
The same is true of any field that stores anything that is not a simple text value, like multi-select, page link, repeaters, relationship, post object, checkbox, taxonomy, flexible content, file, gallery, true/false, user, google map, date picker, time picker, and date/time picker fields.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.