Skip Navigation

[Resolved] How to get author picture stored in custom image field?

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to display an iamge stored in a Types User Field, but the Views shortcodes wpv-user and wpv-post-author don't seem to be working correctly.

Solution: Use the Types Field API types_render_usermeta or the Types Field shortcode to display an image from a Types User Custom Field.

Shortcode example:

[types usermeta="your-field-slug" alt="blue bird" width="300" height="200" proportional="true" user_is_author="true"][/types]

PHP API example:

types_render_usermeta("your-field-slug", array( "alt" => "blue bird", "width" => "300", "height" => "200", "proportional" => "true", "user_is_author" => "true" ) );

Relevant Documentation: https://toolset.com/documentation/customizing-sites-using-php/functions/#image

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by himanshuS 3 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1899751

I have a custom post type called portfolio. I am creating a single post for this post type on registration using custom code.

This post type will be visible to the user and will host their portfolio.

I am enabling user registration through toolset but don't want the user to provide profile picture info on registration. I am also using edit user form to enable user to add more information. However, the edit user form does not allow me to add the wordpress profile_picture field in the form, which prevents me from editing user's profile picture. As a workaround, I have created a custom image field that allows user to add an image to their profile.

Now I want to show the image stored in custom field on the portfolio post. I tried the following but all of them have limitations:
1) [wpv-post-author] does not extract data from custom fields. The meta fields are also of no use and profile_picture shows the image added on registration by default (not the image I want)
2) [wpv-user] does not work either as when I try to pass author id in the code as shown below.

<?php global $wpdb;
$author_id = do_shortcode('[wpv-post-author format="meta" meta="ID"]');
$author_picture = do_shortcode('[wpv-user field="wpcf-profile-picture" id="$author_id"]');
print_r($author_picture);
?>

What am I missing here?

#1900555

As a workaround, I have created a custom image field that allows user to add an image to their profile...Now I want to show the image stored in custom field on the portfolio post.
Hello, if you want to display a Types custom field from the User profile, neither of the shortcodes you mention are designed for that. Instead, you should use a Types usermeta field shortcode or the types_render_usermeta API, as described here: https://toolset.com/documentation/customizing-sites-using-php/functions/#image
Click "+More" to see examples and information about each accepted attribute. Shortcode example:

[types usermeta="your-field-slug" alt="blue bird" width="300" height="200" proportional="true" user_is_author="true"][/types]

PHP API example:

types_render_usermeta("your-field-slug", array( "alt" => "blue bird", "width" => "300", "height" => "200", "proportional" => "true", "user_is_author" => "true" ) );
#1900587

Chris,

Well, that was easy 🙂

I should have read the document in more detail. Thanks, man.

Regards,
Himanshu

#1900589

My issue is resolved now. Thank you!