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);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.