• Hey there,

    I’m trying to run a SQL query to fetch the first name of a user, can anyone tell me what I’m doing wrong with this as it returns nothing:

    SELECT meta_value FROM wp_usermeta WHERE user_id=’1′ AND meta_key=’first_name’

    The above should in theory get the first name of the administrator by going into the wp_usermeta table and pulling the first name from the meta_value column.

    Thanks,
    S

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Does the user have a first name? Probably not. Especially for user 1, which is added when the site is set up and for which no real name is prompted for when the user is added.

    Thread Starter Fabbstar

    (@fabbstar)

    Hi there,

    Thanks for the reply. Yes all users have a first name including the Administrator.

    My feeling is that the SQL syntax is incorrect?

    S

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Nope,your syntax is correct. It works on my site.

    Why are you going directly to SQL rather than doing a query through the API? https://codex.wordpress.org/Class_Reference/WP_User_Query

    Thread Starter Fabbstar

    (@fabbstar)

    Hi,

    Thanks so much for trying it out, at least I know it works!

    I am using SQL due to the requirements of a plugin which allows me to use a text field to pull in data from the WP database using SQL.

    Still can’t get it to work though, I’ll have to see if the plugin author can explain why.

    Thanks again,
    S

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘SQL Query to show User First Name’ is closed to new replies.