I'm glad that solved your problem!
Regarding your question, you see, the first name is not really an s2Member custom field, so it won't be in that array. That array will only have s2Member's custom fields you created that the user's profile has, you can print_r the array to see the contents.
- Code: Select all
<pre><?php print_r($fields); ?></pre>
get_user_field is an s2Member function, doesn't come with WordPress, and will give you
first_name,
last_name and
user_email although they aren't custom fields, to make it more convenient. Sorry about the confusion because of that.
Actually I think it's better that you use the array rather than query each custom field individually, with the array you do a single query for all the fields and then use the ones you need.
Actually, since you don't just need the custom fields but also other data about the user, it's even better if you use the WordPress function get_userdata, which also returns an array with first_name, last_name and much more, including s2Member's custom fields.
- Code: Select all
$user_data = get_userdata($user_id);
print_r($user_data);
The line of code you mention above would be like this
- Code: Select all
echo $data['ID'] . ' - ' . $user_data['first_name'] . ' ' . $user_data['last_name'] . '<br/>';
An s2Member custom field would be here
- Code: Select all
echo 'My custom field is ' . $user_data['wp_s2member_custom_fields']['my_custom_field'];
Now, you're using
$data['ID'], how did you create the
$data array? If you used get_userdata, then you already have it all in
$data.