Home › Forums › Backend Issues (wp-admin) › acf_form() attachment to Media Gallery › Reply To: acf_form() attachment to Media Gallery
Hi,
I did try renaming the function (also in the add_action) but it does nothing. When I select the image from the backend it does get attached by default but from the front end, it does not work. I mean, the image does get saved but it’s not attached to any post.
This is the code I used:
function pb3d_acf_save_post( $post_id ) {
$file = get_field('photo_athlete', $post_id);
if( $file ){
$file_id = $file['ID'];
$post_to_update = array(
'ID' => $file_id,
'post_parent' => $post_id
);
wp_update_post( $post_to_update );
}
}
add_action('acf/save_post', 'pb3d_acf_save_post', 20);
Thanks for your help 🙂
Philippe
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.