So I've been struggling with this but have worked around a lot of it and I thought I'd share what I'd learned.
I'm pretty amazed that there isn't an easier way to do this yet, but I think what I've come up with is reasonably straight forward.
My first discovery was that I could in fact get to the data simply using get_userdata(). Oddly, as far as I can tell (i'm running WP3.1 and s2member 3.5.6), the data is not stored in an json array but rather just a regular array.
To get a custom s2member field for a specific user:
- Code: Select all
$person = get_userdata( ID );
echo $person->wp_s2member_custom_fields["custom_field_key"];
"ID" is a user's ID and "custom_field_key" is whatever field you want to retrieve.
Next, I combined this with the new (as of WP 3.1) get_users() function:
- Code: Select all
$nwfa_members = get_users();
foreach ($nwfa_members as $user) {
$s2_data = get_userdata($user->ID);
echo $user->display_name . ' - City: ' . $s2_data->wp_s2member_custom_fields["s2_city"];
}
In this case, I displayed "[USERNAME] - City: [CUSTOM_CITY_FIELD]".
I couldn't find anyway for get_users() to get the wp_s2member_custom_fields directly, hence the intermediate step of grabbing the user ID and then using get_userdata to get the s2 custom fields.
I am NOT a PHP programmer so it's possible that there are wildly better ways to do this. However, this seems like a step in the right direction, if nothing else.
Please give me feedback if you have any. I'm using this to put together a member directory on my site.