Skip to:
Content

BuddyPress.org

Changeset 6470


Ignore:
Timestamp:
10/29/2012 01:11:04 PM (12 years ago)
Author:
boonebgorges
Message:

Modifications to BP_User_Query to make member searches work correctly

  • Don't pass invalid function parameter when doing user_id search. Props DJPaul
  • Introduce $no_results property (borrowed from WP_Tax_Query)
  • When a member search returns no results, ensure that the user query also returns no results

See #4060

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-classes.php

    r6342 r6470  
    100100    public $uid_name = '';
    101101
     102    /**
     103     * Standard response when the query should not return any rows.
     104     *
     105     * @since BuddyPress (1.7)
     106     * @access protected
     107     * @var string
     108     */
     109    protected $no_results = array( 'join' => '', 'where' => '0 = 1' );
     110
     111
    102112    /** Methods ***************************************************************/
    103113
     
    286296            } else {
    287297                // If the user has no friends, make sure the query returns null
    288                 $sql['where'][] = "0 = 1";
     298                $sql['where'][] = $this->no_results['where'];
    289299            }
    290300        }
     
    296306        // @todo remove need for bp_is_active() check
    297307        if ( false !== $search_terms && bp_is_active( 'xprofile' ) ) {
    298             $found_user_ids = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE %s", '%%' . like_escape( $search_terms ) . '%%' ), ARRAY_N );
     308            $found_user_ids = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE %s", '%%' . like_escape( $search_terms ) . '%%' ) );
    299309
    300310            if ( ! empty( $found_user_ids ) ) {
    301311                $sql['where'][] = "u.{$this->uid_name} IN (" . implode( ',', wp_parse_id_list( $found_user_ids ) ) . ")";
     312            } else {
     313                $sql['where'][] = $this->no_results['where'];
    302314            }
    303315        }
Note: See TracChangeset for help on using the changeset viewer.