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?
-
1If 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.– Jacob PeattieAug 25, 2021 at 13:21
-
Thank you! Good to know!– YuriéAug 25, 2021 at 14:39
1 Answer
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 );
-
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.– vloodAug 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