Skip to content

Instantly share code, notes, and snippets.

@dwanjuki
Last active January 27, 2026 13:42
Show Gist options
  • Select an option

  • Save dwanjuki/f939da8a1a0a0c3905a5b80570f8668b to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/f939da8a1a0a0c3905a5b80570f8668b to your computer and use it in GitHub Desktop.
Exclude a user field from usermeta search
<?php
/**
* Filter directory search conditions to exclude a specific field from usermeta search
*
* 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_sql_search_where( $sql_search_where, $s ) {
$sql_search_where = "
AND (
u.user_login LIKE '%" . esc_sql( $s ) . "%'
OR u.user_email LIKE '%" . esc_sql( $s ) . "%'
OR u.display_name LIKE '%" . esc_sql( $s ) . "%'
OR ( um.meta_value LIKE '%" . esc_sql( $s ) . "%' AND um.meta_key != 'field_name' )
)
";
return $sql_search_where;
}
add_filter( 'pmpro_member_directory_sql_search_where', 'my_pmpro_member_sql_search_where', 10, 2 );
@dwanjuki
Copy link
Author

dwanjuki commented Jul 7, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment