User custom fields not showing in author page
Support › MB User Meta › User custom fields not showing in author page
- This topic has 8 replies, 2 voices, and was last updated 3 months ago by
Peter.
-
AuthorPosts
-
January 3, 2025 at 5:05 PM #47294
sandrinerodrigues
ParticipantHello,
I am working with Metabox AIO and Blocksy Pro.
I want to do a directory, each user can access to its own profile to modify it. So I decided to use MB User Profile, and added custom fields to user.
Everything is fine (Edit profile, register new user, archive of users using WP Grid builder).But I don't achieve to get a single profile for each user.
1. Is the author archive the good solution ? Is each user the actual author of its author archive ?
2. Since I cannot have Metabox field in the author title (event with Post Types Extra from Blocksy Pro), I use a content block and choose to display custom fields with MB Views.
But it works only for one admin : https://www.annuairedev.amalyon.fr/author/maxime_adm/
The other ones cannot retrieve the CF, including me, connected or not : https://www.annuairedev.amalyon.fr/author/sandrine/Here is an exemple of a view I set :
<p><strong> Année de naissance : </strong>{{ author.date_de_naissance | date( 'Y' ) }}</p> <p><strong> Adresse : </strong>{{ author.adresse }}</p> <p><strong> Téléphone : </strong>{{ author.numero_de_telephone }}</p> <p><strong> Email : </strong><a href="mailto:{{ user.email }}">{{ author.email }}</a></p>
If you could tell me where I am wrong, it would be perfect.
Thank you,
SandrineJanuary 4, 2025 at 11:47 PM #47305Peter
ModeratorHello,
Yes, you can use the author archive page to show the user meta in the frontend. If the user meta is only displayed on the admin author page, can you please recheck if other users have the value for custom fields (user meta)?
January 6, 2025 at 4:16 AM #47309sandrinerodrigues
ParticipantThank you Peter,
yes the users do have the value in the custom fields...
See on this screenshot : https://prnt.sc/G6cJjaeCtguq - You can see the user account backend, the empty one frontend, and the MB view which is called by a shortcode (working, since the text in the view is displayed)
The field is filled in the back office user profile, and also on the edit user profile page.
It doesn't appear frontend...January 6, 2025 at 10:52 PM #47316Peter
ModeratorHello,
Please share your site admin account by submitting this contact form https://metabox.io/contact/
I will take a look.January 7, 2025 at 8:51 PM #47325Peter
ModeratorHello,
I fix the issue by using the helper function rwmb_meta() to get the user meta by ID
{% set user_id = mb.get_current_user_id() %} <p><strong> Adresse : </strong>{{ mb.rwmb_meta( 'adresse', {object_type: 'user'}, user_id ) }}</p>
This happens because you use the shortcode on the Blocksy template and other users are not the author of the template so it won't display the meta value.
Following the documentation
https://docs.metabox.io/extensions/mb-user-meta/#getting-field-value
https://docs.metabox.io/functions/rwmb-meta/January 10, 2025 at 4:06 PM #47362sandrinerodrigues
ParticipantThank you Peter for clarifying that. But there is still a problem : I would like to see every user profile, not only my profile, when I'm connected.
And I am not sure if I understood well :
the user "john" is connected and can edit his profile with MB edit profile, which works fine.
John should have access to his profile on front end /author/john, but also every other profiles of registered people.
Every other connected user should see /author/john.So I understand "other users are not the author of the template ", but when you call "current user id" it will call the connected user and not retrieve the other users data ?
Is there a way to achieve what I need ? I am really thinking about creating a CPT dedicated to the profile user, don't you think it would work better ? (Even if I found more elegant to use User Profile MB features, I am stuck since too many days on this...)
Thank you,
January 13, 2025 at 10:10 PM #47387Peter
ModeratorHello,
I change the code from
{% set user_id = mb.get_current_user_id() %}
to
{% set user_id = mb.get_queried_object_id() %}
to get the current query user ID and it shows the user (author) info correctly. Just a WordPress function to get the user ID, not an issue of MB Views or Meta Box.
January 15, 2025 at 3:58 AM #47409sandrinerodrigues
ParticipantThanks a lot Peter, I learned this new function, get_queried_object_id, that will help a lot in the future !
So I made this view working.
There is only one thing with another view. On the same page, I am calling a cloned field.
> 'instrument_de_musique' is a Group
>> 'instrument' and 'niveau' are the two sub-fields (select) of this cloneable group.Following the same logic, I used the queried object but I don't know how to use it as the clones :
{% set user_id = mb.get_queried_object_id() %} {% for clone in mb.rwmb_meta( 'instrument_de_musique', {object_type: 'user'}, user_id ) %} {{ mb.rwmb_meta( 'instrument', {object_type: 'user'}, clone ) }} - {{ mb.rwmb_meta( 'niveau', {object_type: 'user'}, clone )}} {% endfor %}
Nothing is displayed. Is rwmb_meta the correct function ? Which arguments should I give ?
January 15, 2025 at 10:34 PM #47417Peter
ModeratorHello,
You should use the helper function rwmb_meta() to get the group field value at once. To get the subfield value in a group, you can read more about using PHP code in the documentation https://docs.metabox.io/extensions/meta-box-group/#examples
then do the same with Twig code in the View template.
https://docs.metabox.io/extensions/mb-views/#twigIt will look like
{% for clone in ... %} {{ clone.instrument }} {% endfor %}
-
AuthorPosts
- You must be logged in to reply to this topic.