Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I parse the value of a checkbox xProfile field


  • dwdutch
    Participant

    @dwdutch

    I have an xProfile field named Specialty and defined as type=checkbox with 4 options: Area1, Area2, Area3 and Area4.

    I can retrieve a specific members settings for this field via the following two lines of PHP:

    get_var(“SELECT `value` FROM wp_bp_xprofile_data WHERE `user_id` = $id AND `field_id`= $fieldID”); ?>

    For example, the output for someone with Area1, Area2 & Area4 checkmarked is a:3:{i:0;s:5:”Area1″;i:1;s:5:”Area2″;i:2;s:5:”Area4″;}

    This appears to be some type of encoded array but I can’t find anything that explains the format.

    I think I’ve figured out that (a:3) above means an Array of 3 elements and the first element (i:0;s:5:”Area1″) means the key is an integer of value 0 pointing to a string of 5 characters who value is Area1

    MY QUESTIONS:
    1) is this format documented anywhere?
    2) are there bp_* functions already defined that will properly parse this information?

Viewing 1 replies (of 1 total)
  • That’s a serialize()’d array, which is a storable representation of a value. It looks like an array. You need to un-serialize it. You don’t need to use a direct SQL query for that, either, and if you were, you need to use $wpdb->prepare() for security. But I’d suggest doing it like so:


    $your_var = maybe_unserialize( xprofile_get_field_data( $fieldID, $id ) );
    echo var_dump( maybe_unserialize( $your_var ) );

Viewing 1 replies (of 1 total)
  • The topic ‘How do I parse the value of a checkbox xProfile field’ is closed to new replies.
Skip to toolbar