Support

Account

Forum Replies Created

  • Was able to get it working! Thank you for the help!

  • $post_id = attachment_url_to_postid($image_url);

    This code is returning the correct post ID, by the way. I am able to retrieve the text values correctly using get_field on the field group, and then grabbing the array values by field name; except for the true-false fields.

  • I’m still having trouble with true-false values. In the above example, there are 2 true-false switches (checkboxes):

    $artfile = $artwork[‘artfile’];
    $availability = $artwork[‘art-availability’];

    From what I read in the documentation, these should be returning 1 for true or 0 for false. However, they are returning empty, regardless of being checked or not. Any ideas?

  • 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
Viewing 4 posts - 1 through 4 (of 4 total)