Helping you Build Your Own Social Network!

Faster, better and easier!

if function to detect bp_profile_field_data PLEASE HELP!!!

(3 posts) (2 voices)
  • Started 1 year ago by flatoutfab
  • Latest reply from flatoutfab

Tags:

No tags yet.


  1. First off, this request for help is not Buddy DEV related. I am hoping that someone can help me with their expertise! Thank you in advance!

    I have several custom profile fields in my Buddypress installation. I have completely removed profile_loop and created a custom table that uses the bp_profile_field_data function to post specific field data. It works well.

    My problem is that if no data exists for a particular field, the table has a blank spot. I want to create an if function that will look for bp_profile_field_data (field=field_name’). If field_name exists, I want the if function to to echo the field_name ID as a title. If no field data exists I want there to be a no title.

    Posted 1 year ago #
  2. hi
    You can use this as an alternative

    xprofile_get_field_data( $field, $user_id = null )

    And example of use will be

    $data=xprofile_get_field_data("field_name",$user_id);//where user_id is the user for which you want data, on profile page, It will be $bp->displayed_user->id;
    if(!empty($data))
    		{
    //code for table heading and showing data
    }

    Hope it gives you an idea.
    Please let me know if I understood the problem or interpreted it incorrectly?
    Thanks
    Brajesh

    Posted 1 year ago #
  3. Your code did not work, but It certainly opened the window! I was able to do some google searching on xprofile_get_field_data and came up with a few similar examples - nothing exact though. After messing around I came up with this:

    '<tr><?php if ( $fieldName = xprofile_get_field_data('Field Name') ) : ?><?php echo "
    <th>Field Name</th>
    <td>$fieldName</td>
    " ?></div><?php endif; ?></tr>'

    The code is pretty compact imo. I am surprised more people wouldn't need this.

    Posted 1 year ago #

Reply

You must log in to post.