Support

Account

Home Forums General Issues Image fields not attaching to post on post update

Helping

Image fields not attaching to post on post update

  • Hello,
    An acf frontend form is responsible of updating several images in an existing post.
    Problem is:
    The images are saved to the data but not attached to the post – which leaves the just now edited post without images.
    I looked it up and it seems to be a problem many familiar with, tho the answers I found wasn’t helping me much .
    I would appreciate your help guys
    Here is the code:

    add_action('acf/save_post', 'changing_images');
    function changing_images($post_id){
      
      //checking if its the images form by cheking the featured image field
      $profile_pic = $_POST['acf']['field_607d6236e63ff'];
      
      if(isset($profile_pic)){
    
      //creating array to update the current post and attach the images to it
      $logo = get_field('company_logo', $post_id);
      $cover_photo = get_field('תמונת_רקע', $post_id);
      $data = array (
        $profile_pic,
        $logo,
        $cover_photo
    );
    //attachment
    foreach($data as $item):
        $update_post = array(
            'ID' => $item,
            'post_parent' => $post_id
        );
       wp_update_post($update_post);
       endforeach;
      }else{
          return;
      }
    }

    Any help would be good =]
    Thanks you in advance

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

You must be logged in to reply to this topic.