4

Does anyone know how to get access to user meta data on the wordpress backend? I'm trying to see if there is a "user_(linkedin, instagram, facebook, etc)_url". I'm working with a custom php file, and there is an arr called $data that is being created like this:

        $fields = [
            'headshotID' => 'medicus-headshot',
            'firstname' => 'first_name',
            'lastname' => 'last_name',
            'title' => 'medicus-title',
            'biography' => 'medicus-biography',
            'address1' => 'medicus-address1',
            'address2' => 'medicus-address2',
            'city' => 'medicus-city',
            'state' => 'medicus-state',
            'zip' => 'medicus-zip',
            'phone' => 'medicus-phone',
        ];
        
        foreach ($doctors as $doctor) {
            $data = [];
            
            foreach ($fields as $key=>$val) {
                $data[$key] = get_user_meta($doctor->ID, $val, true);
            }

For the key-value pairs in $fields, it seems (I'm guessing) the "values" are the key names in the user metadata table, which contains the following per wordpress docs: ID, user_login, user_pass, user_nicename, user_email, user_url, user_registered, user_activation_key, user_status and display_name (https://developer.wordpress.org/plugins/users/working-with-user-metadata/)

I've logged into phpmyadmin and have looked at the wp_users and wp_metadata tables and I do not see any columns for social media url's.

Is this user metadata table the same place where the values in $fields are being stored? If yes, are there also values for the user's social media information? I'm trying to display the user's info for their social media, specifically the url to their profiles. Is there a "user_linkedin_url", or "user_instagram_url", or anything like that?

I came across this post, but it wasn't very helpful. Maybe I missed something.

In the user wp backend image I attached, you'll see info for the user. I'm trying to display the user's social media url, like their instagram url for instance. How can I do that?

enter image description here

UPDATE (mods and fellow more experienced devs, edit where you see fit. I feel sharing this info is helpful to beginner wordpress devs and should be shared with the community)

1 year update (yikes). To answer my own questions:

  • Is this user metadata table the same place where the values in $fields are being stored?

YES

  • If yes, are there also values for the user's social media information?

Yes, if there are meta_keys that specifically hold information about the user's social media information. In my case, there were actual meta_keys for 'instagram' and 'facebook'. Logging into PhpMyAdmin, I performed this query: SELECT * FROM wp_usermeta WHERE meta_key= "facebook", and sure enough, a bunch of results came up showing users with facebook info.

  • Is there a "user_linkedin_url", or "user_instagram_url", or anything like that?

There can be, if you create custom fields and give them those meta_key names. However, in my particular case, those meta_keys didn't exist. The meta_keys were instead just called 'linkedin' and 'instagram', respectively.

3
  • Did you ever resolve? Looking for the same answer myself. Commented Jul 2, 2020 at 3:32
  • @roadsunknown I have answered this question, but check your case if it is Yoast SEO or not.
    – Bikram
    Commented Jul 3, 2020 at 18:08
  • 1
    Hi @roadsunknown, yes, I actually figured it out on my own shortly after I created this post last year. I never came around to answering my own question. I did a lot of trial and error, but eventually figured out that get_user_meta(id, meta_key, true) was what I needed. @Bikram answered it well. wp_usermeta is the table with all user info.
    – sansae
    Commented Jul 5, 2020 at 5:17

1 Answer 1

5

Use get_user_meta( $user->ID, 'facebook' , true );

But let me clarify you, none of the social media fields are WP core fields. You are using Yoast SEO, and these fields are Yoast SEO features. FYI: I see Yoast SEO from your screenshot.

They are stored on the wp_usermeta table with the social media name in lowercase as the keys. For example, the Facebook URL is saved as facebook key, the Instagram URL is saved as instagram key.

I also misunderstood them as core WP usermeta fields.

Also, the fields could be from other plugins as well, so do plugin deactivation test to figure out the source of update_user_meta().

1
  • 1
    I think you may be correct about the social media fields being from Yoast SEO. At the time, I assumed they were custom fields added by the previous developers who worked on the website I was working on. After all, you can actually add custom fields to user profiles like this. So that's what I thought. Anyway, I did a google search a minute ago and found this. That may or may not be helpful to @roadsunknown
    – sansae
    Commented Jul 5, 2020 at 5:29

Your Answer

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

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