WC_Query::get_main_search_query_sql()
Based on WP_Query::parse_search
Method of the class: WC_Query{}
No Hooks.
Return
null
. Nothing (null).
Usage
$result = WC_Query::get_main_search_query_sql();
WC_Query::get_main_search_query_sql() WC Query::get main search query sql code WC 9.5.1
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 ) . '%'; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $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 ); }