Support

Account

Home Forums General Issues Custom User Photo Field

Solving

Custom User Photo Field

  • I added a photo field to user profiles and uploaded all the photos. I uploaded all the photo URLs to the new photo field but it shows “No image selected” in the profiles. Is there a way to use the photo path in the field to show the user’s picture on their profile. I have over 500 users so doing it manually would take too long.

    Thanks for the help!

    Ben

  • Not sure exactly what you mean. What type of field is it? Where did you upload the images? Please post the code that’s not working for you and on what page or template you’re using it on.

  • John:
    Thank you fr helping me!

    I’m moving an old php website to WordPress and have lots of information on each user including a photo file name. With ACF I was able to add all the custom fields to the User profile and I added one called Photo. Using WP Upload Pro I uploaded all the user data including the WordPress photo path to the photos and I put all the actual photos in the media library. An example of the photo path I uploaded to the new custom field called Photo is this http://localhost/fortier63/wp-content/uploads/2015/10/GreenwaldCynthia.jpg. This doesn’t result in the photo showing in Photo field on the profile page. The photo field on the profile page has a button for you to look up the photo in the media library.

    Is there a way using ACF to add a photo to the user profile without doing each one individually. I have 500 users with photos.

    Thanks!

    Ben

  • Using ACF, unfortunately, no. The only way to do it without coding would be to edit all 500+ users and select the right image for each.

    How good are you with PHP and MySQL?

  • I guess I’m a little rusty at PHP and MySQL? ACF has got me quite spoiled.

    Thanks for all the help! I think I’ll have to just figure it out. Any suggestions would be appreciated.

    Ben

  • So, this is what I would do, and this is because it’s only something that I’d need to use once. I’d build a php script that connected directly to the WP database.

    Search the user table and get the list of users and needed user data

    Loop through each user and construct a string to use to look for the image

    search the post table column guid or post_name LIKE %$name_value% and get the ID of the attachement

    Each record for and ACF field requires two entries in the usermeta table

    INSERT INTO wp_usermeta (user_id, meta_key, meta_value) VALUES ("$user_id", "$acf_field_name", "$post_id"), ("$user_id", "_$acf_field_name", "$acf_field_key")

    I’d do some testing with one or two users to make sure it works and delete anything it added so you don’t get duplicates. Make sure you back up the database. Then I’d set it up to run as a cron job because this will likely timeout if you try to run it in a browser.

  • John:

    That’s a big help. I’ll try to do that next. I think I have the general idea.

    Thanks again for all this help!

    Ben

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Custom User Photo Field’ is closed to new replies.