Home › Forums › General Issues › Gallery: Related Images "Uploaded to"… Problem! › Reply To: Gallery: Related Images "Uploaded to"… Problem!
Oh, I completely missed this! I’m so sorry. Thanks so much for your help. The formatting got a bit wonky but I fixed it up as best as I could and ended up with this code:
add_action('acf/save_post', 'remove_att_from_att');
function remove_att_from_att($post_id) {
$post_type = get_post_type($post_id);
if ($post_type != 'attachment') {
return;
}
$children = get_children($post_id);
if ($children) {
// remove filter so this filter does not run again
remove_filter('acf/save_post', 'remove_att_from_att');
foreach ($children as $child) {
$child->parent = 0;
wp_update_post($child);
}
// restore filter
add_action('acf/save_post', 'remove_att_from_att');
}
}
Which, unfortunately, didn’t work; the images still get attached every time I save a post. Did I make a mistake with my tweaks or is there something else missing?
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.