Better search handling

This commit is contained in:
Mike Jolley 2016-07-19 14:09:56 +01:00
parent d326930d89
commit d79f21a501
1 changed files with 5 additions and 10 deletions

View File

@ -361,23 +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->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id )
INNER JOIN {$wpdb->terms} AS terms USING( term_id ) INNER JOIN {$wpdb->terms} AS terms USING( term_id )
" . $tax_query_sql['join'] . $meta_query_sql['join']; " . $tax_query_sql['join'] . $meta_query_sql['join'];
$query['where'] = " $query['where'] = "
WHERE {$wpdb->posts}.post_type IN ( 'product' ) WHERE {$wpdb->posts}.post_type IN ( 'product' )
AND {$wpdb->posts}.post_status = 'publish' AND {$wpdb->posts}.post_status = 'publish'
" . $tax_query_sql['where'] . $meta_query_sql['where'] . " " . $tax_query_sql['where'] . $meta_query_sql['where'] . "
AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ") AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
"; ";
if ( is_search() ) {
$search_terms = $wp_query->query_vars['search_terms']; if ( $search = WC_Query::get_main_search_query_sql() ) {
$count = 0; $query['where'] .= ' AND ' . $search;
$query['search'] = " AND (";
foreach ( $search_terms as $search_term ) {
$query['search'] .= $count > 0 ? " AND " : "";
$query['search'] .= "(({$wpdb->posts}.post_title LIKE '%" . $search_term . "%') OR ({$wpdb->posts}.post_excerpt LIKE '%" . $search_term . "%') OR ({$wpdb->posts}.post_content LIKE '%" . $search_term . "%'))";
$count++;
}
$query['search'] .= ")";
} }
$query['group_by'] = "GROUP BY terms.term_id"; $query['group_by'] = "GROUP BY terms.term_id";
$query = apply_filters( 'woocommerce_get_filtered_term_product_counts_query', $query ); $query = apply_filters( 'woocommerce_get_filtered_term_product_counts_query', $query );
$query = implode( ' ', $query ); $query = implode( ' ', $query );