• Resolved jeppe

    (@jeppeskovsgaard)


    This probably isn’t related to ACF, but since your plugin is awesome, and I use it for everything except custom posts (including WooCommerce products) I’ll leave this request here.

    I would love to be able to add cropping functionality for all custom post types including WooCommerce products. You could say, that I could just add an ACF image crop field to all posts and hide the standard image feature. If I do so however, I’ll miss out on all native image functionality and compatibility with other plugins using the standard image feature.

    Is there a way to add your image cropping field to all posts, which handles the cropping as a middleman, and then passes it on to the native WordPress image functions (or however that works), so that I could still take advantage of native functions like get_the_post_thumbnail etc.?

    • This topic was modified 4 years, 7 months ago by jeppe.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author joppuyo

    (@joppuyo)

    Hey, I agree it would be useful if you could use this plugin with the standard featured image field but it’s unfortunately out of scope for this plugin.

    If you want to do it on theme level you could try the code I’ve posted here.

    Here’s the snippet:

    add_action('acf/save_post', function ($post_id) {
        $value = get_field('my_crop_image_field', $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);
    Thread Starter jeppe

    (@jeppeskovsgaard)

    Thanks a lot! This works like a charm!

    • This reply was modified 4 years, 7 months ago by jeppe.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Replace image selection for custom posts’ is closed to new replies.