Home Forums Backend Issues (wp-admin) Update Post Meta (User Field)


Update Post Meta (User Field)

  • Hello, hoping someone can help me sort this out:

    I am using Gravity Forms to create a CPT post from the front end. The post has a custom field, multi-select User Field. The form has an Email field. When form is submitted it updates the post meta for the user field with the user associated with the email address.

    My issue is when viewing the post edit in the WP backend, the user is labelled with the site administrators email address, even though it is indeed the proper user associated with the user field. Any ideas on how to have the proper user’s information/name/email displayed in the user field?

    This is the code I am using to update post meta:

    update_post_meta($theId, 'customer', $entry[10]);

  • Going to need more information.

    What type of ACF field is being used on the backend form?

    What is in the value $entry[10]?

  • Hi John,

    User Field, with multiple select ON is being used in the backend.

    $entry[10] is the users email address from a gravity form.

  • A user field in ACF stores the user ID. With a user field that allows multiple selections it stores an array of user ID values. The reason that you’re seeing the wrong value is that the email address is somehow confusing ACF.

    Assuming that customer is the ACF field name. You need to use the email address to look up the user id and then insert that id as part of an array. You should also insert the ACF field key value as well. There is information on ACF field keys on this page

  • Ah yes of course! Thanks for the simple solution John 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Update Post Meta (User Field)’ is closed to new replies.