Support

Account

Home Forums Add-ons Gallery Field Programmatically Inserting Photos Into ACF Gallery Field, But…. Reply To: Programmatically Inserting Photos Into ACF Gallery Field, But….

  • It almost works but because he is missing the “not” operator it fails to add the first entry. Here is the pseudo code.

    $gallery_array = get_field($key, $post_id, false);
    
    if (!is_array($gallery_array )) {
    	$gallery_array = array();
    }
    
    $gallery_array [] = $img_attachment_id;
    update_field($key, $gallery_array , $post_id);