Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom profile field – how to use in theme?


  • zoltok
    Participant

    @zoltok

    Hi there,

    Sorry for the topic as I know it’s similar to other questions that have been asked, but I haven’t found my exact answer yet.

    I am hoping to add an extra field to my registration process that asks people if they are members of a particular group. This data would be queried to an external database (er, if possible – if not I guess we can verify it manually, or take people at their word!).

    I would like to then use this data to display their comments in a slightly different manner (indicating they are members).

    I am a bit of a loss as to where to start with this, particularly with accessing custom field data in themes. Would someone be able to point me in the right direction?

    TIA!

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

  • zoltok
    Participant

    @zoltok

    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.


    zoltok
    Participant

    @zoltok

    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.


    zoltok
    Participant

    @zoltok

    Just wondering, does anyone have any thoughts on this? Still at a bit of a loss as to how to approach this…


    zoltok
    Participant

    @zoltok

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom profile field – how to use in theme?’ is closed to new replies.
Skip to toolbar