Merge branch 'pr/11431'
This commit is contained in:
commit
f9c6764ecd
|
@ -690,6 +690,40 @@ class WC_Query {
|
|||
return $meta_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on WP_Query::parse_search
|
||||
*/
|
||||
public static function get_main_search_query_sql() {
|
||||
global $wp_the_query, $wpdb;
|
||||
|
||||
$args = $wp_the_query->query_vars;
|
||||
$search_terms = isset( $args['search_terms'] ) ? $args['search_terms'] : array();
|
||||
$sql = array();
|
||||
|
||||
foreach ( $search_terms as $term ) {
|
||||
// Terms prefixed with '-' should be excluded.
|
||||
$include = '-' !== substr( $term, 0, 1 );
|
||||
|
||||
if ( $include ) {
|
||||
$like_op = 'LIKE';
|
||||
$andor_op = 'OR';
|
||||
} else {
|
||||
$like_op = 'NOT LIKE';
|
||||
$andor_op = 'AND';
|
||||
$term = substr( $term, 1 );
|
||||
}
|
||||
|
||||
$like = '%' . $wpdb->esc_like( $term ) . '%';
|
||||
$sql[] = $wpdb->prepare( "(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like );
|
||||
}
|
||||
|
||||
if ( ! empty( $sql ) && ! is_user_logged_in() ) {
|
||||
$sql[] = "($wpdb->posts.post_password = '')";
|
||||
}
|
||||
|
||||
return implode( ' AND ', $sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* Layered Nav Init.
|
||||
*/
|
||||
|
|
|
@ -361,12 +361,18 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
INNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id )
|
||||
INNER JOIN {$wpdb->terms} AS terms USING( term_id )
|
||||
" . $tax_query_sql['join'] . $meta_query_sql['join'];
|
||||
|
||||
$query['where'] = "
|
||||
WHERE {$wpdb->posts}.post_type IN ( 'product' )
|
||||
AND {$wpdb->posts}.post_status = 'publish'
|
||||
" . $tax_query_sql['where'] . $meta_query_sql['where'] . "
|
||||
AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
|
||||
";
|
||||
|
||||
if ( $search = WC_Query::get_main_search_query_sql() ) {
|
||||
$query['where'] .= ' AND ' . $search;
|
||||
}
|
||||
|
||||
$query['group_by'] = "GROUP BY terms.term_id";
|
||||
$query = apply_filters( 'woocommerce_get_filtered_term_product_counts_query', $query );
|
||||
$query = implode( ' ', $query );
|
||||
|
|
Loading…
Reference in New Issue