Skip to:

How to create custom query based on xprofile data

  • We run a dating service, and we’re trying to get our members onto our new web-based system backgrounded by WordPress 3.0.1 and Buddypress (current version). I am trying to configure a couple extra pages so that once a user is registered, they can look for people based on age, income, etc…

    We currently ask questions on our resgister page to determine age, who the person’s looking for, gender, yearly income, etc…

    What I am trying to do, is on the members page (all members), have extra tabs or within the header menu, have a drop down to choose only certain members based on their gender. Essentially –
    *Browse Members – (Header Menu)
    -Browse Men – (Tabs on members page, drop down from header)
    -Browse Women – (Tabs on members page, drop down from header)

    Currently I am passing a variable via ?s= in the url. This is sort of (I stress SORT OF) working, in the sense that it’s pulling members with “Gentleman” in their wp_bp_xprofile_data.value field. The problem is, some women are pputting in their looking for “A kind hearted gentleman”, thus, when the query is sent, it’s pulling them into the male members. I also had the gender set as ‘Male’ and ‘Female’ respectively, and it was pulling all female members into that as well, because the query was evidently wildcarding before the ‘Male’ that was passed via the url.

    Where might I be able to write a custom query into the core so when a user clicks to browse men, it pulls only men, and women only women? More specifically, the field_id that’s set in our database is number ’44’. Essentially I would need a query that would pull from the ‘value’ field WHERE the field_id = ’44’ and the user_id = ‘?’, so all the users would be aligned to their gender.

    Another option I thought of would be to somehow enable changing the value passed from the registration page – for instance ‘male’ = ‘1’, and ‘female’ = ‘2’, and then when querying, it would pull in and transform based on the number.

    I’m not new to PHP programming, however I am very much new to wordpress and buddypress, and I’m not sure how to do something like this. I have googled for days, and found nothing that is helpful to my situation. So, please, if you would, take it easy on me, if there is some simple workaround.

    Thanks a million for your time everyone, I really appreciate it.

Viewing 1 replies (of 1 total)
  • the bp_xprofile has a table with variables user_id, field_id, value. so if you have a field_id (gender) = x then it is easy to use a query which checks which value is set for a particular user.
    you can use the function to fetch the right stuff. hope this is putting on the right direction

    xprofile_get_field_data( “fieldname”);

Viewing 1 replies (of 1 total)
  • The topic ‘How to create custom query based on xprofile data’ is closed to new replies.
Skip to toolbar