Title: Custom Orderby sorting
Last modified: September 11, 2019

---

# Custom Orderby sorting

 *  [DAM](https://wordpress.org/support/users/damland/)
 * (@damland)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/custom-orderby-sorting/)
 * Hello,
 * I’ve add a custom orderby to sort members by their points balance, and it works
   but when I try to search by their xprofile using your plugin it doesn’t work 
   anymore.
 * This is the code I’m using: [https://www.mycred.me/tutorials/buddypress-sort-members-by-current-balance/](https://www.mycred.me/tutorials/buddypress-sort-members-by-current-balance/)

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

 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/custom-orderby-sorting/#post-11922971)
 * Hello damland,
 * Please comment out the line:
 * `$BP_User_Query->uid_clauses['select'] = ...`
 * Does that help?
 *  Thread Starter [DAM](https://wordpress.org/support/users/damland/)
 * (@damland)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/custom-orderby-sorting/#post-11925996)
 * [@dontdream](https://wordpress.org/support/users/dontdream/) No, without that
   line it doesn’t work
 * You can use this for tests, it search for a value inside user_meta
 *     ```
       function users_sortby_points( $object ) {
           global $wpdb;
   
       	// Adjust SELECT
       	$object->uid_clauses['select'] = "
       	SELECT $wpdb->usermeta.user_id AS id
       	FROM $wpdb->usermeta";
   
       	// Adjust WHERE
       	$object->uid_clauses['where'] = "WHERE $wpdb->usermeta.meta_key = 'userpoints'";
   
       	// Adjust ORDER BY
       	$object->uid_clauses['orderby'] = " ORDER BY $wpdb->usermeta.meta_value";
   
       	// Adjust ORDER
       	$object->uid_clauses['order'] = 'DESC';
       }
       add_action( 'bp_pre_user_query', 'users_sortby_points' );
   
       function add_sortby_point() {
       echo '<option value="points">Points</option>';
       }
       add_action( 'bp_members_directory_order_options', 'add_sortby_point', 1, 0 );
       ```
   
    -  This reply was modified 6 years, 9 months ago by [DAM](https://wordpress.org/support/users/damland/).
    -  This reply was modified 6 years, 9 months ago by [DAM](https://wordpress.org/support/users/damland/).
 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/custom-orderby-sorting/#post-11927946)
 * Hi damland,
 * I should reproduce your environment on my test site to debug this problem, but
   trying to reproduce someone else’s installation takes a lot of work, and I’m 
   unable to do it.
 * I am willing to take a look at people’s actual installations, but this is against
   [the policy of this forum](https://wordpress.org/support/guidelines/). If you
   are interested, you can use my [Contact](https://dontdream.it/contact/) page 
   to continue this conversation.

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

The topic ‘Custom Orderby sorting’ is closed to new replies.

 * ![](https://ps.w.org/bp-profile-search/assets/icon.svg?rev=1568973)
 * [BP Profile Search](https://wordpress.org/plugins/bp-profile-search/)
 * [Support Threads](https://wordpress.org/support/plugin/bp-profile-search/)
 * [Active Topics](https://wordpress.org/support/plugin/bp-profile-search/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bp-profile-search/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bp-profile-search/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/custom-orderby-sorting/#post-11927946)
 * Status: not resolved