Home › Forums › ACF PRO › Auto populate custom field with user data › Reply To: Auto populate custom field with user data
I actually take that back on the second bit of code. Since the field does not exist yet you must use the field key
add_action('acf/save_post', 'update_name_provider_field');
function update_name_provider_field($post_id) {
if (is_admin()) {
// don't run in admin
return;
}
if (get_post_type($post_id) != 'YOUR CUSTOM POST TYPE')) {
// don't run if not your post type
return;
}
// use the acf field key here
update_field('field_01234567', get_current_user_id(), $post_id);
}
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.