Last active
May 24, 2021 14:08
-
-
Save willybahuaud/48514c5bd16a75c6905eab9a2a9b7ac7 to your computer and use it in GitHub Desktop.
rechercher par mot clé api wordpress
This file contains 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 | |
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