admin管理员组

文章数量:1333442

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 (/)

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?

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.

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/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?

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.

Share Improve this question edited Jul 5, 2020 at 5:49 sansae asked Jul 3, 2019 at 17:56 sansaesansae 1892 silver badges10 bronze badges 3
  • Did you ever resolve? Looking for the same answer myself. – roadsunknown 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
Add a comment  | 

1 Answer 1

Reset to default 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().

本文标签: How to get user metadata for social media url