[buddypress-trac] [BuddyPress Trac] #5839: BP_XProfile_Query - filtering user query results by xprofile field matches

buddypress-trac noreply at wordpress.org
Mon Aug 25 14:37:07 UTC 2014


#5839: BP_XProfile_Query - filtering user query results by xprofile field matches
--------------------------+-----------------------
 Reporter:  boonebgorges  |      Owner:
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  2.2
Component:  XProfile      |    Version:
 Severity:  normal        |   Keywords:  has-patch
--------------------------+-----------------------
 It's not currently possible, without jumping through hoops, to get a list
 of users who match a given set of xprofile terms. This limits BP's use as,
 for instance, a membership directory, since a common use case is to do a
 query like "Show me all the users who live in Chicago and have more than 3
 sisters".

 `BP_XProfile_Query` is inspired by `WP_Meta_Query`. It enables you to pass
 an `xprofile_query` parameter to `BP_User_Query`, of the following format:

 {{{
 'xprofile_query' => array(
     'relation' => 'AND',
     array(
         'field_id' => 12,
         'value' => 'Chicago',
         'compare' => 'LIKE',
     ),
     array(
         'field_name' => 'Number of Sisters',
         'value' => '3',
         'compare' => '>',
         'type' => 'NUMERIC',
     ),
 ),
 }}}

 This example shows a couple features:
 - multiple 'compare' possibilities (inherited from `WP_Meta_Query`)
 - ability to have multiple clauses, separated by an AND or OR 'relation'
 - pass 'field_name' if you don't know 'field_id', and `BP_XProfile_Query`
 will look it up for you

 The fields that generated a match are also put into the
 `BP_User_Query->results` array, so that if you want to display the matched
 content in the loop, you don't have to query for it
 (`BP_User_Query->results[ user_id ]->xprofile_matched_fields`)

 `BP_XProfile_Query` is totally abstracted into the bp-xprofile component,
 and hooks into `BP_User_Query` using the 'bp_pre_user_query' and
 'bp_user_query_populate_extras' hooks. This means (a) no need for
 `bp_is_active()` checks, and (b) I can use the class as a plugin until
 it's rolled into BP core :)

 For the time being, I'm not proposing to expose any of this new
 functionality in a UI in BP core. I am going to work on my existing plugin
 bp-better-directories http://wordpress.org/extend/plugins/bp-better-
 directories/ to use this new functionality. We can decide at a later date
 whether it's possible or feasible to build a UI that is general enough to
 include in core. In the meantime, I'm sure that this API-level stuff will
 be of great use to developers. See #4796 for a related discussion.

 Feedback welcome.

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5839>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list