• Resolved jeppe

    (@jeppeskovsgaard)


    I’ve added an image aspect ration crop field to posts. To set it as the standard featured image, I’m using this:

    add_action('acf/save_post', function ($post_id) {
    	$screen = get_current_screen();
    	if($screen->post_type == 'product' || $screen->post_type == 'post'){
    		$value = get_field('post_featured_image', $post_id);
    		if($value) {
    			if(!is_numeric($value)) {
    				$value = $value['ID'];
    			}
    			update_post_meta($post_id, '_thumbnail_id', $value);
    		}else{
    			delete_post_meta($post_id, '_thumbnail_id');
    		}
    	}
    }, 11);

    I have added an ACF field to all attachments. I would normally get that field like so: $image_copyright = get_field('image_copyright', get_post_thumbnail_id());

    However, because I’m using your plugin for the featured image of the post, the image ID is not the same as the original image from the media library, which means my field is obviously not showing up.

    Is there a way to retrieve the ID of the original image/attachment, so that I can display the field added to the original image?

    • This topic was modified 4 years, 4 months ago by jeppe.
    • This topic was modified 4 years, 4 months ago by jeppe.
Viewing 1 replies (of 1 total)
  • Thread Starter jeppe

    (@jeppeskovsgaard)

    Never mind. The ID of the original image is in the returned array. 🙂

    • This reply was modified 4 years, 4 months ago by jeppe. Reason: Resolved
    • This reply was modified 4 years, 4 months ago by jeppe.
Viewing 1 replies (of 1 total)
  • The topic ‘How to get the ID of the original image?’ is closed to new replies.