Skip to content

Instantly share code, notes, and snippets.

@willybahuaud
Last active May 24, 2021 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willybahuaud/48514c5bd16a75c6905eab9a2a9b7ac7 to your computer and use it in GitHub Desktop.
Save willybahuaud/48514c5bd16a75c6905eab9a2a9b7ac7 to your computer and use it in GitHub Desktop.
rechercher par mot clé api wordpress
<?php
add_filter('terms_clauses', 'w_term_search_clauses', 10, 3 );
function w_term_search_clauses( $clauses, $taxonomies, $args ) {
if ( ! empty( $taxonomies ) && in_array( 'product_cat', $taxonomies ) ) {
if ( ! empty( $args['search'] ) ) {
global $wpdb;
$like = '%' . $wpdb->esc_like( $args['search'] ) . '%';
$clauses['join'] .= " INNER JOIN {$wpdb->termmeta} AS tm ON t.term_id = tm.term_id";
$clauses['where'] = preg_replace( '/\)$/', $wpdb->prepare(" OR (tm.meta_key = 'analog_search' AND tm.meta_value LIKE %s))", $like ), $clauses['where'] );
}
}
return $clauses;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment