Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Created July 17, 2026 14:25
Show Gist options
  • Select an option

  • Save Crocoblock/b74ca577490dc4f00d28ffceb3842d88 to your computer and use it in GitHub Desktop.

Select an option

Save Crocoblock/b74ca577490dc4f00d28ffceb3842d88 to your computer and use it in GitHub Desktop.
Search Filter by first and last name and by user ID
<?php
add_filter( 'jet-smart-filters/query/final-query', function( $query ) {
if ( empty( $query['meta_query'] ) ) {
return $query;
}
foreach ( $query['meta_query'] as $index => $meta_query_item ) {
// Check for our custom marker key (e.g., user_prop__multi_search)
if ( isset( $meta_query_item['key'] ) && false !== strpos( $meta_query_item['key'], 'user_prop__multi_search' ) ) {
$search_value = $meta_query_item['value'];
// 1. Configure search by standard database columns (including ID)
$query['search'] = '*' . $search_value . '*';
$query['search_columns'] = array( 'ID', 'user_login', 'user_nicename' );
// 2. Add search by metafields (first_name and last_name) using OR relation
$query['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => 'first_name',
'value' => $search_value,
'compare' => 'LIKE',
),
array(
'key' => 'last_name',
'value' => $search_value,
'compare' => 'LIKE',
),
);
// Remove the temporary marker so it doesn't break the main query
unset( $query['meta_query'][$index] );
}
}
return $query;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment