Last active
December 21, 2023 20:36
-
-
Save kimcoleman/5415228af102c580584cd44c24bd157c to your computer and use it in GitHub Desktop.
Only search the PMPro Member Directory for matching usernames or display names.
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
<?php | |
/** | |
* Only search the PMPro Member Directory for matching usernames or display names. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_member_directory_sql_search_where_username_display_name_only( $sql_search_where, $s ) { | |
// Limit search to username and display name only. | |
$sql_search_where = "u.user_login LIKE '%" . esc_sql( $s ) . "%' OR u.display_name LIKE '%" . esc_sql( $s ) . "%'"; | |
// Alternate query, limit search for username, email, and display name. | |
//$sql_search_where = "u.user_login LIKE '%" . esc_sql( $s ) . "%' OR u.user_email LIKE '%" . esc_sql( $s ) . "%' OR u.display_name LIKE '%" . esc_sql( $s ) . "%'"; | |
// Build a new query | |
$sql_search_where = ' AND ( ' . $sql_search_where . ' ) '; | |
return $sql_search_where; | |
} | |
add_filter( 'pmpro_member_directory_sql_search_where', 'my_pmpro_member_directory_sql_search_where_username_display_name_only', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment