Skip to:
Content
Pages
Categories
Search
Top
Bottom

Function/Call to access Custom Profile Fields?

  • @shedmore

    Participant

    Okay, I have been browsing the site up and down…and I feel like I am missing something obvious…sorry if it has already been answered, but I couldnt find it.

    What is the best approach (is there a function or api) to access custom fields within a plugin I want to create….or do I have to do it through sql directly.

    Lets say I setup a plugin that wants to evaluate whether to do something based on the age of a member. The age is a custom text field I created in the profile field setup in the buddypress admin….

    How can I actually get & set THAT custom xprofile data for use in the plugin?

    If this sets the display_name

    xprofile_set_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $usermeta[‘display_name’], $user_id );

    Then is there something that is similar to set data to a “custom” field like my age example…and vice versa, whats the best way to “get” the data too

    I hope my question is clear, but if it isnt please let me know

    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • @shedmore

    Participant

    Anybody???

    I could really use the help please!

    @apeatling

    Keymaster

    xprofile_get_field_data( $field_name_or_id, $user_id );

    @shedmore

    Participant

    Thanks Andy, I appreciate it. I can see it now…I will dig through the bp-xprofile.php to figure out the other functions.

    Thanks for the great work!

    @shedmore

    Participant

    Andy let me ask you….I am playing with the bp-facebook plugin you ported, and specifically trying to add a value to the insert function you have in there now

    function bp_fbconnect_insert_data( $user_id, $usermeta )

    ///////I tried setting an extra value inside that function – statically for now (just for testing) right under the default “full name” insert you have in there now.

    I set it up like this:

    xprofile_set_field_data(‘Age’, $user_id, ‘Test’);

    I have tried setting with double quotes, no quotes, and several different ways, but it never seems to insert into the “Age” field I created in Buddypress.

    Any ideas whats going wrong here? I am wondering if this function isnt firing at the right time? OR maybe I am making a stupid mistake :)

    Thoughts? Thanks

    @shedmore

    Participant

    Okay….Andy is probably busy, I didnt mean to explicitly ask Andy (only) :)…if anyone has any advice on this I would appreciate it!

    @damoncook

    Participant

    I’m attempting to do something kinda similar. I just want to create a block (pardon my Drupal lingo) that shows a blog’s author information in my theme. I want to specifically show their BP custom fields.

    Right now I’ve copied over bp-sn-parent/profile/profile-loop.php to my theme and called: locate_template( array( 'profile/profile-loop.php' ), true ) but this gives me everything in the user’s profile. I would like to get a little more granular and just specify certain fields. hmmm

    Here is my current example as it exists.

    @shedmore

    Participant

    For some reason…no matter what I try, I can’t inject SPECIFIC variables via the xprofile_set_field_data function….I run this function (below)

    ONLY AFTER running two conditionals to make sure

    /////////

    ONE the buddypress globals are set

    and

    TWO the check for the xprofile function passes

    Both conditionals pass (as expected) then go to my test function below

    ////////

    End result — The echo statement appears correctly…but nothing is appearing in the field values for the user – I am pulling my hair out??????

    Sample

    ////////

    function BP_Insert_Test($wpuid, $age) {

    $age = ’22’; // Should appear in the profile

    echo(‘user id is ‘ . $wpuid . ‘ and userdata is ‘ . $age);

    xprofile_set_field_data(2, $wpuid, $age);

    }

    Any ideas?

    @shedmore

    Participant

    Okay…I have more details from my testing. It works now, but I am not really sure WHY. It seems to me that you have to (for some reason) call the get_field_data function (even if its on a useless peice of data) before you can use the set_field_data function.

    If you notice from my post above…the only thing that is different is that I have added a new variable that is simply capturing the Name field (number 1). Well when I add this:

    $nametestfield = xprofile_get_field_data(1,$wpuid);

    And then the set_field after it (with my age variable)…than it starts working, and the field is inputted.

    SO….Is there a reason why you can’t call the set_field independently. Calling in the name is basicaly useless in the function above, but it DOES make the whole thing work for some reason.

    ///////////////////////////////

    function BP_Insert_Test($wpuid, $age) {

    $age = ‘tester gender’;

    $nametestfield = xprofile_get_field_data(1,$wpuid);

    echo(‘user name exists already’ . $wpuid . ‘ and userdata is ‘ . $age);

    echo(‘Need Field is’ . $nametestfield);

    xprofile_set_field_data(2, $wpuid, $age);

    }

    @shedmore

    Participant

    Anybody have ideas on the post/question above????

    @aslamdoctor

    Member

    I’m also facing same issue.. even I added manually insert query inside code like this (I have stored the values in session)

    $sql=”INSERT INTO wp_bp_xprofile_data (field_id, user_id, value) VALUES(1,$curr_id, ‘”.$_SESSION.”‘)”;
    result=mysql_query($sql)or die(mysql_error());

    This is storing the data in database but not retrieving :(
    @shedmore did u got this fixed up ???

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Function/Call to access Custom Profile Fields?’ is closed to new replies.
Skip to toolbar