Home › Forums › General Issues › how to display the author's name › Reply To: how to display the author's name
Hi @flexi2202,
Is your form only visible to logged in users? I assume you’re logged in as non-admin?
I think you need to use the acf_form() parameters
On of the parameters is: html_after_fields.
As you’re logged in, you can access the user ID:
$user_id = get_current_user_id();
So you could then use a hidden value:
'html_after_fields' => '<input type="hidden" name="acf[author_id]" value="'.$user_id.'"/>',
Using acf/save_post
You can then grab the hidden value and updated the post author:
add_action('acf/save_post', 'my_acf_save_post');
function my_acf_save_post( $post_id ) {
$arg = array(
'ID' => $post_id,
'post_author' => $_POST['acf']['author_id']
);
wp_update_post( $arg );
}
Code is untested but should point you in the right direction
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.