Page 1 of 1

Displaying Custom Member Fields

PostPosted: August 3rd, 2011, 3:17 pm
by AaronHolbrook
I did a couple searches here and on google and couldn't find anything.

I'd think this would be fairly straightforward - since adding custom registration fields is easy, but I can't figure out what function to use to call to get those custom registration fields to display out (like in a member directory).

Any ideas where to look?

Re: Displaying Custom Member Fields

PostPosted: August 3rd, 2011, 11:21 pm
by Cristián Lávaque
Hi Aaron.

You can do something like

Code: Select all
$user = get_user_option('s2member_custom_fields', $user_id); 


Here's a example use of that viewtopic.php?f=4&t=6546&p=16582#p16582

I hope that helps. :)

Re: Displaying Custom Member Fields

PostPosted: August 4th, 2011, 8:23 pm
by AaronHolbrook
Thanks Cristian.

Just in case anyone else was needing a good way to query the database for the custom registration fields this is what I did. The only issue is that parsing the database for unserialized data could potentially be insecure and come back to bite you in the ass if they ever change the serialization function for arrays.

Code: Select all
add_filter('posts_where', 'a7author_search_where' );

function a7author_search_where($a7auth_param) {
   global $wpdb;

   $querystr = "
      SELECT       $wpdb->usermeta.user_id
      FROM       $wpdb->usermeta
      WHERE       $wpdb->usermeta.meta_value LIKE '%post_code%" . $a7auth_param . "%'
      
   ";

   $author2 = $wpdb->get_results($querystr);
   
   return $author2;
}

Re: Displaying Custom Member Fields

PostPosted: August 5th, 2011, 1:06 am
by Cristián Lávaque
Thanks Aaron. :)

Would that example get you members that have a certain post code?

Re: Displaying Custom Member Fields

PostPosted: August 5th, 2011, 7:33 am
by AaronHolbrook
yea exactly - my custom registration field setup through s2member was post_code, and I needed to return results based on a search query, so that's a way I figured out how to search the database looking for that information.

I'll post something more inclusive when I'm all finished.

Re: Displaying Custom Member Fields

PostPosted: August 5th, 2011, 10:30 pm
by Cristián Lávaque
Great. :)