Home › Forums › Backend Issues (wp-admin) › Default to current user with user field › Reply To: Default to current user with user field
Hi!
I honestly think you’ll be better of creating this yourself..
simply do an update_post_meta on the wp_save_post hook.. something like this (not tested):
function save_book_meta($post_id) {
$slug = 'book'; //CHANGE THIS TO THE SLUG OF YOUR POST TYPE
/* check whether anything should be done */
$_POST += array("{$slug}_edit_nonce" => '');
if ( $slug != $_POST['post_type'] ) {
return;
}
if ( !current_user_can( 'edit_post', $post_id ) ) {
return;
}
$current_user = wp_get_current_user();
update_post_meta($post_id, 'latest_author', $current_user-> display_name);
}
add_action( 'save_post', 'save_book_meta');
This will save the current users display name as a custom field called “latest_author”.
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.