Skip Navigation

[Resolved] How to display User’s custom fields on author archive

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

Problem: I would like to display the Author User's custom field information in an Author archive, but the Types usermeta field shortcode does not seem to work.

Solution: You must include the Author's User ID in the user_id attribute in an Author archive. Unfortunately there is no built-in way to retrieve that Author's User ID simply. It requires a custom shortcode. Add the following code in your child theme's functions.php file, or to a new code snippet in Toolset > Settings > Custom Code:

function get_author_id_in_archive_func($atts) {
  return get_the_author_meta('ID');
}
add_shortcode("get-author-id-in-archive", "get_author_id_in_archive_func");

This shortcode will return the User ID of the author in the current WordPress Archive.

Then go to Toolset > Settings > Front-end Content > Third party shortcode arguments and register get-author-id-in-archive. This will allow you to use the new custom shortcode as an argument in the Types usermeta field shortcode. Now your nested Types field shortcode syntax can use the user_id attribute like this:

[types usermeta='imya-na-russkom' user_id='[get-author-id-in-archive][/get-author-id-in-archive]'][/types]

Place this nested shortcode inside your WordPress Archive before the opening wpv-loop tag.

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

This support ticket is created 4 years, 9 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)

Author
Posts
#1551311

How can I use my custom fields on the users archive pages?

For example:

I have my own custom fields for users: Name, Surname, Avatar
And I want to use their on the author archive pages, like hidden link

let's say I want to display user name (my custom field, not standart WP field) inside subtitle - hidden link (hidden link)

I use shortcode - [types usermeta='imya-na-russkom'][/types] - hidden link

But it does not work, I get empty space - hidden link

How can I fix it?

#1551339

Hello, this one is a bit tricky and it requires a custom shortcode to retrieve the author's ID inside the archive. Please add the following code in your child theme's functions.php file:

function get_author_id_in_archive_func($atts) {
  return get_the_author_meta('ID');
}
add_shortcode("get-author-id-in-archive", "get_author_id_in_archive_func");

This shortcode will return the User ID of the author in the current archive.

Then go to Toolset > Settings > Front-end Content > Third party shortcode arguments and register get-author-id-in-archive. This will allow you to use the custom shortcode as an argument inside the Types usermeta field. Now your Types field shortcode syntax can use the user_id attribute like this:

[types usermeta='imya-na-russkom' user_id='[get-author-id-in-archive][/get-author-id-in-archive]'][/types]

Let me know if you have questions about this, or if the shortcode does not work correctly.

#1551445

Thanks for your advice but, for some reason, it did not help.

I tried to add code inside my functions.php file

 
function get_author_id_in_archive_func($atts) {
  return get_the_author_meta('ID');
}
add_shortcode("get-author-id-in-archive", "get_author_id_in_archive_func");

But got error hidden link . Because I am using Toolset Communication System on my site, and I already made similar action and already have shortcode [get-author-id-in-archive][/get-author-id-in-archive] - hidden link

So, I tried to use the shortcode [types usermeta='imya-na-russkom' user_id='[get-author-id-in-archive][/get-author-id-in-archive]'][/types].

And got nothing - hidden link (hidden link)

Next, I tried to modify you code and added number 2 at the end - hidden link and registered get-author-id-in-archive-2 - hidden link

And then I modified shortcode - hidden link

But it did not bring to me any new results too - hidden link

#1552145
Screen Shot 2020-03-16 at 9.05.05 AM.png

Okay if you already have get_author_id_in_archive, that should work without needing to add more code. I tried to edit this archive and test using your original shortcode but I'm seeing several JavaScript errors. The errors are blocking any updates, so I cannot save changes here: https://new.shadyladycam.com/wp-admin/admin.php?page=view-archives-editor&view_id=608

I will try adding another archive as a test, and give you an update shortly. Please stand by.

#1552761

I think the problem is caused by the plugin "Accordions by PickPlugins" I disabled it, now nothing should be blocked during the update.

#1553103

My issue is resolved now. Thank you!