1

I am having an issue:

I don't know why this happens.

Regarding user metadata, when should I use one or the other?

I tried this:

get_the_author_meta('afzfp_user_status', $user->ID);
get_user_meta('afzfp_user_status', $user->ID, true);

It returns:

String "the meta value"
bool (false)

UPDATE:

(As pointed by @shanebp) - The parameters order is different, that is why my code is not working as expected:

get_the_author_meta('afzfp_user_status', $user->ID);
get_user_meta($user->ID, 'afzfp_user_status', true);

The question itself still remains: What is the difference between them and when is it recommended to use one or the other?

2
  • Can you include the code you ran for both of them? The parameters and how they're called are important – Tom J Nowell Jun 9 '20 at 20:54
  • @TomJNowell Thanks for your attention, I updated my question with sample code. – Álvaro Franz Jun 9 '20 at 21:04
2

Your parameter order is wrong for get_user_meta. The user id should be first.

Try: var_dump(get_user_meta( $user->ID, 'afzfp_user_status', true));

2
  • This lack of focus should have an associated punishment. Thanks for your help! By the way I will wait before marking your answer as accepted because I still don't know when I should use one or the other. There must be a purpose in having defined two functions to retrieve user metadata. The main difference I see is one accepting the third "return single" parameter, but not sure if that's the whole reason. – Álvaro Franz Jun 10 '20 at 7:51
  • The difference is that get_user_meta has an optional third parameter and the $user_id is required rather than being optional. – shanebp Jun 10 '20 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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