Created
March 9, 2026 10:08
-
-
Save dwanjuki/682334bc158edcd0699b0b0bebcd4904 to your computer and use it in GitHub Desktop.
Update the member directory search sql query to check a single custom field, return exact matches
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 | |
| /* | |
| * Update the member directory search sql query to check a single custom field. | |
| * Return results only if the custom field value exactly matches the search term. | |
| * | |
| * Replace custom_field_name with your custom field name (meta key). | |
| * | |
| * 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( $sql_search_where, $s ) { | |
| $sql_search_where = " | |
| AND ( | |
| um.meta_key = 'custom_field_name' AND um.meta_value = '" . esc_sql( $s ) . "' | |
| ) | |
| "; | |
| return $sql_search_where; | |
| } | |
| add_filter( 'pmpro_member_directory_sql_search_where', 'my_pmpro_member_directory_sql_search_where', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment