Skip Navigation

[Résolu] Views – get user data via a user-id

This support ticket is created Il y a 9 années et 10 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 22 réponses, has 4 voix.

Last updated by tony Il y a 9 années.

Assigned support staff: Adriano.

Auteur
Publications
#63045

I am aware that I can get current user details via [wpv-current-user].

Is it possible to get data relating to a specific user by adding a user id?

What I want to do is create a password protected page whereby selected people can see email addresses of all registered users.

Thanks
Tony

My alternative solution invoves setting up a subscriber post and dupicating the fields that I want access to

#63175

Dear tony,

You need to use some codes and a shortcode to do this. Please take a look in this page, it's a default wordpress function and with it you can to display all users with its data: http://codex.wordpress.org/Function_Reference/get_users#Example

#78778

ok thanks Adriano (sorry for the delay - been looking at other solutions!

I have had a look at this and cannot work out what exactly I need to do.

I have a member record that contains the user-id that relates to the member. Ideally what I want to do is to create a view that returns a list of "memberships" That record contains user-id and member-id amongst other fields.

I would like to display a list of memberships that includes data from members and users. So my report would look something like:

member name {from user data} | email {from user data} | member status {from member data} | joining date {from member data

If I create a parent/child relationship between membership and member, I can get all the member fields. I just need to get the user data fields using shortcodes.

Maybe something like [wpv-user info="email" id="2345"] and [wpv-user info="firstname" id="2345"] [wpv-user info="surname" id="2345"]

( id="2345" relates to the user and is a field in the membership record)

Thanks
Tony

#79583

Dear tony,

I created a custom shortcode for this, please try with it and let me know about the result. Put the code below inside of functions.php file:

add_shortcode( 'wpv-post-userdata', 'wpv_userdata');
function wpv_userdata($atts){
	extract( shortcode_atts( array(
	'field_user' => '',
	'id_user' => '',
	), $atts ) );

	$user_info = get_userdata($id);
	
	if($field_user == 'user_email'){
		return($user_info->user_email);
	}
	if($field_user == 'user_firstname'){
		return($user_info->user_firstname);
	}
	if($field_user == 'user_lastname'){
		return($user_info->user_lastname);
	}
}

As you can see, this custom shortcode will woks only for to get the email, firstname and lastname. So you can use [wpv-post-userdata field_user="user_firstname" id_user="123"]

You will need to use the correct name so, you can see its here: http://codex.wordpress.org/Function_Reference/get_userdata#Notes

I hope that's help you.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#79670

Thanks Adriano

The user ID is defined by this types field: [types field="member-user-id" id="$member"][/types]

Am I right in thinking that I can replace the "123" in your shortcode with this to create:

[wpv-post-userdata field_user="user_firstname" id_user="[types field="member-user-id" id="$member"][/types]"]
[wpv-post-userdata field_user="user_firstname" id_user="123"]

Tony

#79680

Hi Adriano

I tried this and something seems to be wrong.

The function.php has been uploaded and I tried a simple field [wpv-post-userdata field_user="user_firstname" id_user="2"] which did not return anything.

Tony

#80013

Dear tony,

Please replace your code with:

add_shortcode( 'wpv-post-userdata', 'wpv_userdata');
function wpv_userdata($atts){
	extract( shortcode_atts( array(
	'field_user' => '',
	'id_user' => '',
	), $atts ) );

	$user_info = get_userdata($id);
	
	if($field_user == 'user_email'){
		echo($user_info->user_email);
	}
	if($field_user == 'user_firstname'){
		echo($user_info->user_firstname);
	}
	if($field_user == 'user_lastname'){
		echo($user_info->user_lastname);
	}
}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#80030

Hi Adriano

Many thanks for this.

I changed the functions.php and set the following up on my home page as a test:

Details of users<br />
1=[wpv-post-userdata field_user="user_firstname" id_user="1"] [wpv-post-userdata field_user="user_lastname" id_user="1"] [wpv-post-userdata field_user="user_email" id_user="1"]<br />
2=[wpv-post-userdata field_user="user_firstname" id_user="2"] [wpv-post-userdata field_user="user_lastname" id_user="2"] [wpv-post-userdata field_user="user_email" id_user="2"]<br />
3=[wpv-post-userdata field_user="user_firstname" id_user="3"] [wpv-post-userdata field_user="user_lastname" id_user="3"] [wpv-post-userdata field_user="user_email" id_user="3"]<br />

I have 3 users set up 1,2 and 3.

The resulting display was:

Details of users
1=
2=
3=

In theory, this code should work in any WordPress system that has users 1,2 and 3 set up with the function.php code in place.

I cannot see what might be wrong.

Regards
Tony

#80140

Dear tony,

I’ll send you a private email right now asking you for some private information that will help me debug this issue for you. Please check your email in a couple of minutes, and if you don’t get it, let me know so I can send it again.

Thanks.

#80356

Thanks Adriano
Details sent.
Tony

#80633

Dear tony, I'm trying to save the funcions.php file and I can not. Please send me the FTP credentials too.

Many thanks.

#80846

Hello Adriano
Details sent by email
Tony

#80938

Dear tony,

Thanks, I received the credentials and I'm checking it now.

#80962

Dear tony,

I change the shortcode codes and now it works fine. Please check the post named "Test" and the functions.php file.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#81027

Thanks Adriano

That seems to work fine and so I can now construct a membership list that takes data from the user details as well as member details.

Excellent response as per normal.

Regards
Tony