Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/5415228af102c580584cd44c24bd157c to your computer and use it in GitHub Desktop.
Save kimcoleman/5415228af102c580584cd44c24bd157c to your computer and use it in GitHub Desktop.
Only search the PMPro Member Directory for matching usernames or display names.
<?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