• Luke

    (@lukejanicke)


    • get_user_meta()
    • get_userdata()
    • get_the_author_meta()

    These three functions can all take a user ID and be used to retrieve things like Display Name and Email Address. It all seems a little redundant.

    • get_the_author_meta() retrieves one specified item for the author of the current post in the Loop or for the user specific by the given ID.
    • get_userdata() returns an WP_User object for the given user ID.
    • get_user_meta() can return a single item or an array of all items for the given user ID.

    Does anyone have any general advice for where/how each would be best used?

    I’m writing a plugin that sends an email to all editors when a post is published (a lite custom plugin). I need to retrieve names and email addresses for editors. I decided to use get_userdata(), since get_the_author_meta() doesn’t make sense semantically (I’m not dealing with a post, just the fact that a user has the ‘Editor’ role), and dealing with the nested arrays of get_user_meta() is giving me a headache.

  • The topic ‘get_user_meta() vs. get_userdata() vs. get_the_author_meta()’ is closed to new replies.