I am using Ultimate Member on on my site and am trying to pull in the user id of the profile that is generated by Ultimate member so that I can display content of the profile being viewed (as opposed to the logged in user.)
The Ultimate Member documentation offers the following:
This code will retrieve the user id of the profile page when executed on the profile page.
$profile_id = um_profile_id();
So, I created the following shortcode:
//Shortcode to get profile ID
add_shortcode('profile_id', 'profile_id_func');
function profile_id () {
$profile_id = um_profile_id();
return $profile_id;
}
I have registered the shortcode in the Toolset settings on my site, but when I try to use it, it does not display correctly. It just displays "[profile_id]" as if it were text. (I am a super noob at php, so I'm guessing my shortcode code is out of whack. )
Any thoughts?
VJ
It occurred to me that I might be able to accomplish this without involving Ultimate Member.
Here's the issue:
User pages display profile information but I want to add custom content views that show additional content related to the user being viewed. Right now, these views only display information for the logged in user, not the user of the profile page being viewed. The url for each user profile page is site.com/user/username
Is there a way to pull the username from the URL and use it to filter the view?
Hello and thank you for contacting the Toolset support.
Please check this article that explains how to customize the user profile page https://toolset.com/documentation/customizing-sites-using-php/creating-custom-user-profiles/
I understood that you would like to get the id or username of the visited user (site.com/user/username), right?
WordPress does not provide such a feature and Toolset neither.
You can, of course, extract it from the URL using PHP strings functions. But I suggest to pull it from the global WordPress query.
Check this code:
function get_this_user(){
$query = isset( $GLOBALS['wp_query'] ) ? $GLOBALS['wp_query'] : false;
$author = isset( $query['author_name'] ) ? $query['author_name'] : false;
return $author;
}
This function will return the username of the visited user profile or false. You can then use it in your shortcode or register is as function that Toolset could evalute in conditions.
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-custom-functions-in-conditions/
I hope this helps. Let me know if you have any questions.