Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dantetesta/810ed3cdb4b31bbcec0dd91fb07899d4 to your computer and use it in GitHub Desktop.
Save dantetesta/810ed3cdb4b31bbcec0dd91fb07899d4 to your computer and use it in GitHub Desktop.
/* By Luciano Cezareto + Crocoblock */
/* 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;
} );
@maxytetsu
Copy link

Top, salvou minha vida, vlwwww

@VictorPietro
Copy link

Muito obrigado Dante! Como sempre, ajudou demais. Não apenas consegui pesquisar por usuários, como também agora consigo fazer uns filtros bem cabulosos através desse interceptador /final-query.

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