0

I am totally new to wordpress and acf and I'm trying to use a user field in a post to show the author of the post. I tried to programatically add the post author id as a meta attribute in the wp_postmeta table like this:

update_field('video_author', get_current_user_id(), $post_id);

The post author, however, is not shown:

enter image description here

What am I doing wrong?

Also when I click the user field no users are listed. I presume acf looks for users in either "wp_users" or "users" table, both of which contain records. However, this is shown:

enter image description here

Thank you in advance.

2
  • If this is a regular post, the author is already saved in the database. Even if you create the post programatically, if that script is triggered by the logged in user, that user will be the post's author.
    – NightHawk
    Commented Aug 19, 2020 at 17:22
  • @NightHawk But how to I show this user in my post edit page? Commented Aug 21, 2020 at 10:28

1 Answer 1

0

If you are using ACF then you don't need to update field manually. Field will be updated when you update the post.

And To retrieve this field use :

get_field( 'video_author', $post_id );

For User field, make sure you have selected Field Type -> User in ACF.

2
  • I need to create a post programatically (with wp_insert_post) and then to the newly creted post - set it's "video_author" field to the current logged user's id, this is my custom logic. Commented Aug 19, 2020 at 14:28
  • Ok, In that case you can use update_field Commented Aug 19, 2020 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.