Home › Forums › General Issues › Gallery values disappearing, trying to use get_post_meta › Reply To: Gallery values disappearing, trying to use get_post_meta
I think I figured this out. Here’s the code I used to get the URL, credit and description field from the gallery field “photos”:
$photosValues = get_post_meta( $post->ID, 'photos');
foreach ( $photosValues as $photoItem) {
foreach ( $photoItem as $photoID) {
$thePhoto = get_post($photoID);
$photoURL = wp_get_attachment_url($photoID); // gets photo URL
$photoCredit = get_field('credit', $photoID); // gets ACF credit field
$photoDesc = $thePhoto->post_content; // gets description field
echo $photoURL;
echo $photoCredit;
echo $photoDesc;
}
}
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.