Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress Checkbox field data


  • ibrahim_alfors
    Participant

    @ibrahim_alfors

    Hello, so I’m trying to do some coding with buddypress on my own. I’m trying to make a search function in my website where users can search for members using the data from their profiles.

    For example, There are teachers and students on the website. On a page called “Find Teachers”, I want the users to be able to search for teachers using their names and the subjects they teach. A teacher adds these subjects using checkboxes on his profile.

    I have created the query for the searching by name but when I tried to add searching by the checkboxes values I couldn’t understand the way Buddypress handles the checkboxes data in the database. When the teacher checks “English”, “Math” and “Substitute” from the provided choices, the data in the database appears like this:
    a:3:{i:0;s:7:”English”;i:1;s:4:”Math”;i:2;s:10:”Substitute”;}

    Now I want to compare the data the user will insert in the search form with the data in the website but I can’t figure out the way Buddypress Encrypts the data in the database.

    Is there maybe a function included with Buddypress that would encrypt the data from the form to the format in the database or perhaps decrypt the data from the database so I can compare them in a sensible way?

    I really need help with this, thanks guys!

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

  • shanebp
    Moderator

    @shanebp

    a:3:{i:0;s:7:”English”;i:1;s:4:”Math”;i:2;s:10:”Substitute”;}
    is a serialized array.

    BuddyPress will unserialize profile data via
    xprofile_get_field_data( $field, $user_id = 0, $multi_format = 'array' )
    and return an array.

    But if you want to do this in the context of a search query, you probably want to use wildcards in the mysql statement, for example: %math%.
    This can be tricky to implement if you haven’t done it before.

    There is already a good plugin that does member searches based on profile field values:
    https://wordpress.org/plugins/bp-profile-search/


    ibrahim_alfors
    Participant

    @ibrahim_alfors

    @shanebp thank you for the reply.

    I have researched the plugins that allow the searching for members and I found that this plugin is great but unfortunately the requirements of my client need a lot more customization and I find the documentation of buddypress much more helpful.

    About the:
    xprofile_get_field_data( $field, $user_id = 0, $multi_format = 'array' )
    I think using that in a Query would be very expensive as it would require doing more database transaction over the search transaction. Am I right?

    The wild card seems like a decent way to go with it, I think I will try that 🙂

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Buddypress Checkbox field data’ is closed to new replies.
Skip to toolbar