Support

Account

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