Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/25/2014 04:40:27 PM (7 years ago)
Author:
boonebgorges
Message:

Introduce BP_XProfile_Query.

Based on WP_Meta_Query, BP_XProfile_Query is a helper class for generating
queries against users' XProfile data. It allows developers to filter user
queries to those users who have profile data matching a wide range of
comparisons, from simple equality ("city=Chicago") to complex combinations of
various comparison operators.

An 'xprofile_query' argument has been introduced to BP_User_Query to
support use of BP_XProfile_Query inside of bp_has_members() loops.

See #5839.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-filters.php

    r9073 r9178  
    324324
    325325/**
     326 * Parse 'xprofile_query' argument passed to BP_User_Query.
     327 *
     328 * @since BuddyPress (2.2.0)
     329 *
     330 * @param BP_User_Query User query object.
     331 */
     332function bp_xprofile_add_xprofile_query_to_user_query( BP_User_Query $q ) {
     333    global $wpdb;
     334
     335    if ( empty( $q->query_vars['xprofile_query'] ) ) {
     336        return;
     337    }
     338
     339    $xprofile_query = new BP_XProfile_Query( $q->query_vars['xprofile_query'] );
     340    $sql = $xprofile_query->get_sql( 'u', $q->uid_name );
     341
     342    if ( ! empty( $sql['join'] ) ) {
     343        $q->uid_clauses['select'] .= $sql['join'];
     344        $q->uid_clauses['where'] .= $sql['where'];
     345    }
     346}
     347add_action( 'bp_pre_user_query', 'bp_xprofile_add_xprofile_query_to_user_query' );
     348
     349/**
    326350 * Filter meta queries to modify for the xprofile data schema.
    327351 *
Note: See TracChangeset for help on using the changeset viewer.