Skip Navigation

[Resolved] Custom user fields not displaying correctly

This support ticket is created 6 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by David 6 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1115745

Page with problem: hidden link
Description of problem: The content at the top of the right-hand sidebar should display the author photo and bio (both custom user fields created through Types). Currently my photo (as admin or as user 1) is showing and not the author's. This has been working for over a year but has broken recently with one of the updates to Types and Views. My code is as follows:

<div class="author-box">
[types usermeta='user-profile-photo' title='%%TITLE%%' alt='%%ALT%%' align='center' size='medium' resize='proportional' user_is_author='true'][/types]
<h3 style="text-align: center">[wpv-post-author]</h3>
[types usermeta='biography' user_is_author='true'][/types]
</div>
#1116463

Hi David,

Thank you for contacting us and I'll be happy to assist.

The [types] "usermeta" shortcode with attribute user_is_author='true' returns the values for current post's author inside the loop.

But on your website, the shortcode is being used in the sidebar and not inside a post/page content (outside the loop).

To make this work in the sidebar of the author archive page, you can follow these steps:

1. Please, add the following code at bottom of your active child theme’s “functions.php” file:


// custom shortcode to return author id on author archive page
add_shortcode('current_author_archive', 'current_author_archive_fn');
function current_author_archive_fn() {
    
 $author = get_user_by( 'slug', get_query_var( 'author_name' ) );
    return $author->ID;
}

It will add a new shortcode [current_author_archive], which will return the ID of the author, whose author archive page is being viewed.

2. Next, register this new shortcode with Toolset, so it can be used inside its built-in shortcodes, as explained in the following guide:
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/

3. After that you can update your shortcode in the sidebar from:


[types usermeta='user-profile-photo' title='%%TITLE%%' alt='%%ALT%%' align='center' size='medium' resize='proportional' user_is_author='true'][/types]

To:


[types usermeta='user-profile-photo' title='%%TITLE%%' alt='%%ALT%%' align='center' size='medium' resize='proportional' user_id='[current_author_archive]'][/types]

I hope this helps! Please let us know how it goes and if you need any further assistance.

#1117325

Thank you, that worked but how do I get the shortcode [wpv-post-author] to display the name of the author as well? It seems user_id is not a valid parameter for this shortcode so I don't know how or where to insert our custom shortcode. Thank you.

#1117658

I figured out a solution. I'm using the following instead of [wpv-post-author] to take advantage of the custom shortcode you had me create. Thank you again.

<h3 style="text-align: center">[wpv-user field="user_firstname" id="[current_author_archive]"] [wpv-user field="user_lastname" id="[current_author_archive]"]</h3>
#1117659

My issue is resolved now. Thank you!