Created
April 19, 2025 10:34
-
-
Save VictorPietro/66c032cdd7f766d3f547c94234b0a9c3 to your computer and use it in GitHub Desktop.
Pesquisar por E-mail do User e outros campos com JetSmartFilters no WordPress
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
/* Adicione esse trecho no functions.php do tema [ou tema filho mais seguro] */ | |
/* no campo search do smartfilters no query variable coloque: | |
user_prop::user_email; user_prop::user_login; user_prop::user_nicename; user_prop::ID; user_prop::user_url | |
--->> importante use ponto e virgula (;) para adicionar mais de um termo caso necessário. */ | |
/* | |
Veja o Prints: | |
https://imgur.com/a/amQwmzv | |
https://imgur.com/a/3foNmbH | |
*/ | |
add_filter( 'jet-smart-filters/query/final-query', function( $query ) { | |
foreach ( $query['meta_query'] as $index => $meta_query_item ) { | |
if ( false !== strpos( $query['meta_query'][$index]['key'], 'user_prop::' ) ) { | |
$prop = explode( '::', $query['meta_query'][$index]['key'] )[1]; | |
$query['meta_query'][$index]['key'] = $prop; | |
$query['search_columns'] = array( $prop ); | |
$query['search'] = '*'.$query['meta_query'][$index]['value'].'*'; | |
foreach( $query['meta_query'] as $i => $meta_query_item ) { | |
if ( $meta_query_item['key'] == $prop ) { | |
unset( $query['meta_query'][$i] ); | |
} | |
} | |
} | |
} | |
return $query; | |
} ); | |
// Desenvolvido por: Dante Testa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment