1

Just discovered that the get_the_author_meta( 'birth_date', 0 ) returns the administrator birthdate. The same happens with other $field parameters for $user_id = 0. Is this an expected behavior for this function?

2
  • 1
    If the administrator is the author of the post, then yes, this would be expected. If the user ID is missing or false (which 0 is) then it defaults to the author of the current post. Aug 25, 2021 at 13:21
  • Thank you! Good to know!
    – Yurié
    Aug 25, 2021 at 14:39

1 Answer 1

2

Directly on the question - no, the get_the_author_meta() function is not supposed to return you by default the birthday date when you provide 0 for user ID, as it is not a default user meta field. Yet, providing 0 is the same as not providing a user ID at all, hence the function tries to get the author ID from the global $authordata variable.

Looking at the bottom of the code of the function, there is this last line in it, which suggests something (a plugin or the theme) might be messing with you:

    return apply_filters( "get_the_author_{$field}", $value, $user_id, $original_user_id );
3
  • Thank you, I understand now! By the way, my question it is not strictly about the date of birth, but about any field/parameter.
    – Yurié
    Aug 25, 2021 at 14:38
  • @IurieMalai, I guess I misunderstood that you are receiving administrator's birth date no matter what field value you provide. You must be getting the case that Jacob suggested in his comment - doing the check on a post, published by the administrator.
    – vlood
    Aug 25, 2021 at 17:11
  • The Jacob's comment and your answer both helped me to understand what happens. The part "providing 0 is the same as not providing a user ID at all" answered to my question.
    – Yurié
    Aug 25, 2021 at 19:19

Your Answer

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

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