Home › Forums › General Issues › get_field() not returning values on specific post ID for image › Reply To: get_field() not returning values on specific post ID for image
I solved this by first getting the field group and then individually addressing each one:
// Extract the attributes
$atts = shortcode_atts( array( 'src' => '', ), $atts, 'artwork');
// Your PHP code here
$image_url = esc_attr($atts['src']); // sanitize the image URL from the shortcode attribute
$post_id = attachment_url_to_postid($image_url); // get the image post ID from the image URL using the WordPress function
$artwork = get_field('artwork', $post_id); // get artwork field group
$artfile = $artwork['artfile']; // get value of a flag that this is art file media
$title = trim($artwork['art-title']); // get title
$title = trim($title,'"'); // remove quotes
$year = trim($artwork['art-year']); // get year completed
$dimensions = trim($artwork['art-dimensions']); // get dimensions
$medium = trim($artwork['art-medium']); // get medium
$availability = $artwork['art-availability']; // get availability
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.