Support

Account

Home Forums General Issues getfield from user profile

Solving

getfield from user profile

  • I have created a radio button for user profile. Now, getting it out:
    $value = get_field( 'is_premium_customer', 'user_'.get_current_user_id() );

    But it returns nothing. If I manually use ‘user_2’, for example, it can get the field.
    get_current_user_id() returns correct user_id.

    Any idea why?
    Thanks.

  • Possible issues
    1) The currently logged in user does not have a value set
    2) You are calling get_field() before ACF has initialized.

    When/Where are you calling get_field()?

  • Thanks for answering. But I don’t think the code has problem. When I changed field_name “is_premium_customer” to field_key, then I got the value, even the guide here shows usage og field_name.

  • If using the field key works when using the field name does not work this generally indicates that the ACF field key reference is missing from the database.

    Are you using the WP admin and the ACF fields shown there to update the user or are you saving this value by some other means?

  • Yes, I am only using ACF from wp-admin, not using any other tool. And ACF is the latest version. Is that a bug?

  • I doubt there is a bug, I’m not seeing an issue. Something else must be causing the issue.

    Look in the database in the wp_usermeta table. Find the meta key of “_is_premium_customer” the meta value of this should be the field key of the ACF field. If this value is missing or is not the correct field key then you need to find what is altering this. It could be anything, or some filter. Then you need to start deactivating other plugins and maybe switch the theme to figure out what is conflicting with the saving of the acf field key reference value.

  • The meta_value has the key there, which is the same key I see in wp-admin – ACF. So, no missing key in the database.

  • Then the only thing left is that you are trying to get the field value before ACF has initialized. The only way to accomplish that is if you are trying to get the values in a file like function.php or in a plugin before the WP ‘init’ hook is fired.

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

You must be logged in to reply to this topic.