Home Forums Add-ons Gallery Field Idiot Proof an ACF Gallery Reply To: Idiot Proof an ACF Gallery

  • I may have solved this with the below if anyone else ever runs into this issue. It is limited to affecting uploads only to a certain post type. Not sure if you could limit to only uploads via the gallery field somehow…

    function add_filter_upload_image($attach_id){
    $post_id = wp_get_post_parent_id( $attach_id );
    $post = get_post($post_id);
    if($post->post_type == <custom-post-type>){
    $array = get_field(‘field_5f0dcbfc35af4’, $post_id, false);
    if (!is_array($array)) {
    $array = array();
    $array[] = $attach_id;
    update_field(‘field_5f0dcbfc35af4’, $array, $post_id );
    add_filter(‘add_attachment’, ‘add_filter_upload_image’, 10, 1);