Support

Account

Home Forums Front-end Issues acf_form upload featured image error

Solved

acf_form upload featured image error

  • Hi,

    I’m using the front end acf_form to upload posts.
    It’s working fine if i don’t select a image.
    But if i want to upload a image to be the featured image i get the following error:

    Warning: filesize()
    Warning: getimagesize()
    Warning: Cannot modify header information

    If i use the option in the array ‘uploader’ => ‘basic’ is get this error.
    When user ‘uploader’ => ‘wp’ its working fine

    In my functions.php u use this function to set the featured image:

    add_action( ‘acf/save_post’, ‘tsm_save_image_field_to_featured_image’, 10 );
    function tsm_save_image_field_to_featured_image( $post_id ) {

    // Bail if not logged in or not able to post
    if ( ! ( is_user_logged_in() || current_user_can(‘publish_posts’) ) ) {
    return;
    }

    // Bail early if no ACF data
    if( empty($_POST[‘acf’]) ) {
    return;
    }

    // ACF image field key
    $image = $_POST[‘acf’][‘field_575ec9736147a’];

    // Bail if image field is empty
    if ( empty($image) ) {
    return;
    }

    // Add the value which is the image ID to the _thumbnail_id meta data for the current post
    add_post_meta( $post_id, ‘_thumbnail_id’, $image );

    }

    Does anybody know what is going wrong?
    Cheers in advance

  • Hi @geppie030

    If you execute “acf/save_post” with the priority of 10, the image is not processed by WordPress yet. Kindly change it to 20, get the image by using the get_field() function and use the set_post_thumbnail() function to set the featured image instead.

    This page should give you more idea about it: https://www.advancedcustomfields.com/resources/acfsave_post/.

    I hope this helps 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘acf_form upload featured image error’ is closed to new replies.