latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Get values from Custom Field Multiple Select

Home Forums Community Forum Get values from Custom Field Multiple Select

This topic contains 15 replies, has 4 voices. Last updated by  Simon Groves 3 years, 10 months ago.

Topic Author Topic
Posted: Wednesday Feb 13th, 2013 at 6:57 am #41601
Ian Jarvis
Username: jarvis

Hi Guys,

Hope someone can help!? I’ve just installed S2Members Pro (awesome!) and setting up custom fields. I’ve worked out how to return custom fields for standard text but how do I get the value or values from a multiple select?

Your help is very much appreciated. Thanks in advanced

List Of Topic Replies

Viewing 15 replies - 1 through 15 (of 15 total)
Author Replies
Author Replies
Posted: Thursday Feb 14th, 2013 at 8:11 pm #41739
Eduan
Username: Eduan
Moderator

Hello Ian,

What do you mean with a field with multiple selections?

Also, your account doesn’t seem to show you have the pro version, how did you acquire the pro version?

– Eduan

Posted: Friday Feb 15th, 2013 at 4:24 am #41811
Simon Groves
Username: prg

Hi Eduan

Thanks for getting back to me. I think the confusion may come from I’ve ended up with 2 S2Memer accounts. One I initially setup to enquire and one I then had to create for the company in order to purchase the s2member pro licence. I’m more than happy to send through any information to validate our account, simply let me know what you need and who I need to send it to.

As for the query above, I’ve created an additional custom registration field which is a Select Menu with multi-option which I did from here:

General > Profile Fields/options > Custom Registration Fields

However, I can’t work out how I display that information to a user? At the moment, I’m using the following:

#get the user ID from the URL
$theUserID = $_GET["author"];

echo get_user_field('company', $theUserID); 

Which displays the info I need for one of my other fields, I just can’t work out how to display the multi-options in the select?

Any help is much appreciated

Posted: Saturday Feb 16th, 2013 at 2:24 pm #41958
Eduan
Username: Eduan
Moderator

It still doesn’t make sense, what does “multi-options” mean? You mean the dropdown fields?

Also, your account is pro, it’s just beside your avatar. :)

– Eduan

Posted: Monday Feb 18th, 2013 at 3:23 am #42241
Simon Groves
Username: prg

Hi Eduan

Yes the drop down with multiple select. How do I show the values on a page?

Thanks

Posted: Monday Feb 18th, 2013 at 10:11 am #42264
Eduan
Username: Eduan
Moderator

NOT sure if this would work, but you can try this:

// Get the user ID by URL
$userID = $_GET['author'];

// Get user's info
$user_info = get_userdata($userID);

// Get field's value
// Replace `custom_field` with the field's Unique ID that you gave it
$userCustomField = $user_info->custom_field;

Now, this works by using get_userdata(), one of WordPress’ functions.

Again, not sure if this will work, I haven’t tested it myself but it’s worth a shot.

Now, the s2Member way of getting the value of this field would be with the shortcode [s2Get user_field="custom_field" /], so to get this in code you would do something like:

// Get field's value
// Replace `custom_field` with the field's Unique ID that you gave it
$userCustomField = do_shortcode('[s2Get user_field="custom_field" /]');

Hope this gives you some clues. :)
I repeat, you gotta try these first cause I’m not sure if they would work.

Posted: Monday Feb 18th, 2013 at 10:21 am #42268
Simon Groves
Username: prg

Thanks Eduan,

I did as you said, swapping the custom_field to mine but to no avail:

<?php
// Get the user ID by URL
$userID = $_GET['author'];

// Get user's info
$user_info = get_userdata($userID);

// Get field's value
// Replace `custom_field` with the field's Unique ID that you gave it
$userCustomField = $user_info->sector;

// Get field's value
// Replace `custom_field` with the field's Unique ID that you gave it
$userCustomField = do_shortcode('[s2Get user_field="sector" /]');
?>

I’ll play around with this but at the mo, it simply returns nothing

Thanks though

Posted: Monday Feb 18th, 2013 at 11:52 am #42281
Eduan
Username: Eduan
Moderator

I’m sorry it didn’t work. :(
I’ll see if I can figure something out later. If I do I’ll post it here, however again, most probably it will not be tested. ;)

Posted: Monday Feb 18th, 2013 at 11:54 am #42283
Simon Groves
Username: prg

I think it’s because it stores the info as an array (due to being a multiple select). I’m not sure if that helps or not?

Your help is much appreciated though!

Thanks again

Posted: Thursday Feb 21st, 2013 at 11:59 am #42741
Simon Groves
Username: prg

Sorry to post here again but I can’t seem to find a solution. I tried the following code:

$fields = get_s2member_custom_fields();
print_r($fields["sector"]["config"]); # The Unique Field ID you configured with s2Member.


$fields = get_s2member_custom_fields(10);
echo $fields["sector"]["user_value"]; # The Unique Field ID you configured with s2Member.
print_r($fields["sector"]["config"]); # The Unique Field ID you configured with s2Member.

This simply returns the entire contents of the array and not the selected values.

I really can’t see why this is such an issue. It seems a shame that the multi select isn’t covered in the documentation like the standard custom fields

Any help is much appreciated

Posted: Thursday Feb 21st, 2013 at 2:28 pm #42749
Eduan
Username: Eduan
Moderator

Hmm…

Personally I can’t help any more, so I’ll ask Jason for his help, see what he has to say. :)

Posted: Friday Feb 22nd, 2013 at 6:20 am #42792
Simon Groves
Username: prg

Thanks Eduan

I simply can’t find any info on this anywhere – surprisingly! So any assistance here would be awesome

Posted: Friday Feb 22nd, 2013 at 9:32 am #42812
Staff Member

Thanks for the heads up on this thread :-)

Please use s2Member® API Function: get_user_field()

If the value is an array; you will get the array containing the selected values.

Posted: Friday Feb 22nd, 2013 at 9:39 am #42815
Simon Groves
Username: prg

Hi Jason,

Thanks for the reply. I’m a bit of a noob with PHP etc. Are you able to shed any light on code?

The unique field ID is sector and it’s a multi select drop down. I just can’t seem to find code that’ll work. I’ve found code for checkboxes but trying to ‘adapt’ it simply didn’t work.

Any help on this is very much appreciated!

Posted: Friday Feb 22nd, 2013 at 11:00 pm #42895
Staff Member

Thanks for the follow-up :-)

Here is a quick example:

<?php
$user_id = get_current_user_ID();
$user_field_values = get_user_field('my_field_ID', $user_id);

if(is_array($user_field_values))
	{
		foreach($user_field_values as $value)
			echo $value.'<br />';
	}
?>

Replace my_field_ID with the unique ID you assigned the Custom Registration/Profile Field in s2Member.
See: Dashboard -› s2Member® -› General Options -› Registration/Profile Fields

See also: Knowledge Base » ezPHP Plugin for WordPress®

Posted: Saturday Feb 23rd, 2013 at 6:34 am #42987
Simon Groves
Username: prg

Hi Jason,

That is absolutely spot on – thank you!!!!

Viewing 15 replies - 1 through 15 (of 15 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.