Ok, update on progress.
I finally found some examples in the forums of people calling profile data. Here’s what I’ve currently got in my template files, this seems to be working:
$user_id = $comment->user_id;
$isMember = xprofile_get_field_data( 'Member', $user_id );
echo 'Member: '. $isMember;
The field is a radio button with only one option. This returns: a:1:{i:0;s:3:”Yes”;}
I know this is outputting some kind of array, but my knowledge gets a little shaky here. How would I target this data to conditionally do something if the value “Yes” is selected?
What precisely are you trying to do? Style a comment if a user is in a particular group? (is that a BuddyPress Group?)
If so, it’d be best to save that in the ‘commentmeta’ when the comment is saved to the database (saves a query per comment, which could get bad quickly). Let us know and we can help.
Yes, I’m trying to style the comments of a particular group a little differently. The community I’m building is for users and potential clients of a membership-based service. Anyone can sign up, but I’d like to give commenters who are actual members of the service a little bit of a different treatment, so their comments carry more weight. I’m envisioning a small icon that overlays their gravatars indicating they are members.
For the moment I had planned on using xprofile data for this. I don’t have groups enabled (yet), but if we use them in the future, I would like to make them user-controlled for smaller interest groups (whereas membership to this group would be more admin-controlled). We have an external database with the names of all members in it, but I’m not yet sure how to cross-check with that database when users sign up (or if that’s even possible!).
Maybe xprofile data is not the best way to go about this? I know there are role options in WordPress, would this maybe be a better way to handle this? My main concern is ensuring maximum flexibility as the site develops.
Just wondering, does anyone have any thoughts on this? Still at a bit of a loss as to how to approach this…
Ok, thought I’d follow up in case anyone tries to do the same thing.
Here’s the code that ended up working:
$user_id = $comment->user_id;
$isMember = xprofile_get_field_data( ‘Member’, $user_id );
if ($isMember == “”) {
} else {
?>
Abonné
<?php
}
No idea how this would be done if you were testing for more than one checkbox though, but for my use (either checked or not), it worked just fine.