BuddyDev

Search

Cannot retrieve xprofile field data

Tagged: 


  • Participant
    Level: Initiated
    Posts: 2
    medievil on #21536

    Hi,

    I have a strange issue that I cannot figure out.
    I have created a new profile field and I am using the following function to try retrieve the data:

    $phonecheck = xprofile_get_field_data('Show your phone number in website search results?', $bpmember);

    This code is identical to other xprofile fields in the same file and they are retrieving the data fine.
    The only difference is that this particular xprofile field is new, the others were created about 12 months ago.
    I have tried downgrading the plugin to the last couple of versions but to no success.

    Is there some new way to get the xprofile field data that I am not aware of?


  • Keymaster
    Level: Guru
    (BuddyDev Team)
    Posts: 678
    Ravi on #21539

    Hello Medievil,

    Thank you for posting. Please let me know what is the type of this field is. Because if it is a checkbox
    field and user has not selected any of its options then it will give empty string. Also make sure $bpmember is not empty. You can use php function “var_dump” to check what result function is returns

    Thank You
    Ravi


  • Participant
    Level: Initiated
    Posts: 2
    medievil on #21544

    Hi Ravi,

    Thanks for reaching out.
    The field type is a Dropdown Select with two options (Yes & No).

    A var_dump of $bpmember returns the correct integer for that particular member.
    A var_dump of $phonecheck returns a blank string.

    I have an identical function ($emailcheck) that grabs field data from an identical Dropdown Select field and this is returning “Yes” as normal.

    I am at a complete loss as to why this is occurring. I have checked the syntax 10 times and it is identical to a working function.
    It only appears to be happening to newly created xprofile fields, I cannot fetch data from any of them. However I can grab data from the older fields with no problems.


  • Keymaster
    (BuddyDev Team)
    Posts: 11218
    Brajesh Singh on #21545

    Hi,
    Can you please visit the profile of the specific user(You are passing as the second parameter) and confirm that on view profile the data is being shown for new fields?

    The possible reasons are:-
    1. Either data is not set for the given user for the new fields.
    2. Or the Field name is not being parsed to field id. Try using Field id(numeric value in place of field name).

    Let me know what you find.

    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 2
    medievil on #21614

    Hi Brajesh,

    I have found the cause of the issue.

    When creating the dropdown profile field, I set the default option to “Yes”.
    When checking the user’s profile, this shows correctly as “Yes” for this option.

    However after a closer look, the field data is not actually set to this unless I or the user manually update the profile and therefore write the data to the field.
    It seems that because the default option is used, the data only “appears” to be set, where actually it is blank.
    This is what confused me.

    The workaround is to either
    1) Mass-update all user profiles for this field, or
    2) Change the PHP function parameters to check for anything except the default option (“No”, this is what I did).

    As option 1 would cause problems for any newly created profile, I had no choice but to go with option 2.
    Is this something that could be fixed in a future update? You can recreate this issue by creating a profile field with a default option, then exporting user’s data to a CSV. The profile field will be blank.


  • Keymaster
    (BuddyDev Team)
    Posts: 11218
    Brajesh Singh on #21619

    Hi,
    Thank you for the reply.

    This is expected behaviour. You were most probably checking the edit profile page not the view profile page. On View profile you will not see any data related to the field.

    It is an expected behaviour for BuddyPress. You need to save the profile to make the data available. Even though xprofile_get_field_data can be tweaked to return default, I believe writing a warpper is a better solution.

    You may want to create a ticket here and report this to BuddyPress team.
    https://buddypress.trac.wordpress.org/

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved
Subscribe