WC_Query::get_main_search_query_sql()
Based on WP_Query::parse_search
Description Description
Source Source
File: includes/class-wc-query.php
public static function get_main_search_query_sql() { global $wpdb; $args = self::$product_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 ); // unprepared SQL ok. } if ( ! empty( $sql ) && ! is_user_logged_in() ) { $sql[] = "($wpdb->posts.post_password = '')"; } return implode( ' AND ', $sql ); }