Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is there a way to show different content depending on profile fields?


  • gregfielding
    Participant

    @gregfielding

    For example, using if/then statements, if a member’s favorite color is red, they see sidebar A, and if it’s blue, sidebar B.

    I’ve been searching quite a bit and it doesn’t appear that there are buddypress conditional tags for xprofile attributes.

    Any ideas? – Thanks!

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

  • gregfielding
    Participant

    @gregfielding

    Here’s the code I’m trying to use in my sidebar:

    `

    sample code

    `


    gregfielding
    Participant

    @gregfielding

    Trying to call the loggedin_user_id, but doing to wrong…

    `loggedin_user->id) && bp_get_profile_field_data(‘field=783’) === “Yes”) : ?>
    sample code
    `


    Nahum
    Participant

    @nahummadrid

    @gregfielding I forgot where I found this (maybe bp-tricks)

    put this in your bp-custom

    `//CHECK IF THE ACCT IS CERTAIN ACCT TYPE

    function My_Function ($user_id) {
    global $bp;
    $type_member = xprofile_get_field_data( ‘Color’, $user_id );
    if($type_member == ‘Red’) {
    return true;
    } else {
    return false;
    }
    }`

    Then to display in sidebar
    `
    loggedin_user->id)) : ?>
    Red Sidebar

    Some other Sidebar
    `


    Nahum
    Participant

    @nahummadrid

    in the function, where color = your main field heading, I’ve used a dropdown. and Red is one of the drop down items to select from.

    I don’t know if it works the same if the field was just a text field. I imagine so.


    gregfielding
    Participant

    @gregfielding

    Thanks @nahummadrid

    I think it’s closer but still not working right. It only shows “Some other Sidebar”.

    Here’s my code:

    `//CHECK IF THE ACCT IS CERTAIN ACCT TYPE

    function My_Function ($user_id) {
    global $bp;
    $type_member = xprofile_get_field_data( ‘Real Estate Industry Professional’, $user_id );
    if($type_member == ‘Yes’) {
    return true;
    } else {
    return false;
    }
    }`

    I wonder if the issue is that I’m using a checkbox, with the option of “Yes”…


    pcwriter
    Participant

    @pcwriter

    @gregfielding

    Try using boolean values instead. If you want “Some other sidebar” to display if the box is checked, then the value should be “1”. Worth a try…


    Nahum
    Participant

    @nahummadrid

    `loggedin_user->id)) : ?>
    Red Sidebar
    `

    This works though right.


    gregfielding
    Participant

    @gregfielding

    @pcwriter – replacing “Yes” with “1” didn’t work – was that what you meant?


    @nahummadrid
    – yes, that works.


    Nahum
    Participant

    @nahummadrid

    I couldn’t figure out how to display something else…

    I guess you could create different functions for each type of field

    `loggedin_user->id)) : ?>
    Red Sidebar

    loggedin_user->id)) : ?>
    Blue Sidebar
    `

    I wish I knew enough about what all is happening in that piece of code. So that I could make it work the way i proposed. otherwise, there will be a blank sidebar for non logged in users and users who don’t have a xprofile field selected corresponding with those requirements.


    Nahum
    Participant

    @nahummadrid

    don’t know what I just did but this seems to work…

    `loggedin_user->id) == ‘Yes’) : ?>
    Red Sidebar
    <?php elseif(is_user_logged_in()):?>
    Another sidebar
    `

    and you want this to look like this

    `//CHECK IF THE ACCT IS CERTAIN ACCT TYPE

    function My_Function ($user_id) {
    global $bp;
    $type_member = xprofile_get_field_data( ‘Real Estate Industry Professional’, $user_id );
    if($type_member == ‘Yes’) {
    return true;

    }
    }`


    gregfielding
    Participant

    @gregfielding

    ‘if($type_member == ‘Yes’)…`

    Either way, even if I create a second function, It isn’t recognizing the profile field.

    This seems fishy to me. Is $type_member really the way to call a profile field entry? Or could it be a checkbox issue?


    Nahum
    Participant

    @nahummadrid

    yea there’s prolly an easier way to go about it. I’ve just copied/pasted/refreshed different combinations til something worked. :) I look forward to seeing something simple to use for stuff like this. hehe


    Nahum
    Participant

    @nahummadrid

    yet another way to do it, i think…

    `<?php
    global $bp;
    $user_id = $bp->loggedin_user->id;
    $type_member = xprofile_get_field_data( ‘Real Estate Industry Professional’, $user_id );?>

    <?php if($type_member == 'Yes'):?>
    Yes Sidebar
    <?php elseif($type_member == 'No'):?>
    Another Sidebar for this option

    Sidebar for everyone else
    `


    gregfielding
    Participant

    @gregfielding

    Looks much cleaner, but still isn’t working. I tried using a radio button and that didn’t work either.

    What I’m trying to do should be simple :)

    If you are a professional, you get one sidebar. If you are a civilian, you get another. And I’ve got a checkbox on the registration form.

    Thanks for all of your help so far you guys…


    pcwriter
    Participant

    @pcwriter

    @gregfielding

    Just tested the snippet by @nuhammadrid above with a dropdown select and it works perfectly.

    I found this old trac ticket (pre 1.2.6) but maybe checkboxes/radio buttons are stilla bit buggy with xprofile_get_field_data


    pcwriter
    Participant

    @pcwriter


    gregfielding
    Participant

    @gregfielding

    @pcwriter @johnjamesjacoby
    Yup. Bug is definitely still there. Nice find!


    gregfielding
    Participant

    @gregfielding

    As a work-around, I wonder if I could use this plugin https://wordpress.org/extend/plugins/buddypress-xprofiles-acl/ to assign roles based on the profile field answer.

    Then I could more easily show different sidebars depending on roles.

    Not the cleanest way to do it. Has anyone else had trouble with checkboxes?


    Nahum
    Participant

    @nahummadrid

    @gregfielding are you not wanting to use dropdown select for any reason? instead of using checkboxes/radio? Can you have more than one role? If you only need one role per user, why not use dropdown xprofile field and make it required at sign up?

Viewing 19 replies - 1 through 19 (of 19 total)
  • The topic ‘Is there a way to show different content depending on profile fields?’ is closed to new replies.
Skip to toolbar