Created
April 5, 2021 15:24
-
-
Save ideadude/55acb4d0785479de042493fc0ba3061c to your computer and use it in GitHub Desktop.
Sort BuddyPress members by PMPro membership level.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sort BuddyPress members by PMPro membership level. | |
* Add this code as a code snippet or in a custom plugin. | |
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/ | |
*/ | |
function my_sort_bp_members_list( $query ) { | |
global $wpdb; | |
$query->uid_clauses['select'] .= " LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.user_id = mu.user_id AND mu.status = 'active' "; | |
$query->uid_clauses['orderby'] = str_replace( 'ORDER BY', 'ORDER BY mu.membership_id DESC, ', $query->uid_clauses['orderby'] ); | |
} | |
add_action( 'bp_pre_user_query', 'my_sort_bp_members_list', 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment