Compare list is empty.
You will find a lot of interesting products on our "Shop" page.
add_action('pre_get_posts', function ($query) { if (is_admin() || !$query->is_main_query()) { return; } if ($query->is_search() && (isset($_GET['post_type']) && $_GET['post_type'] === 'product')) { $query->set('post_type', 'product'); $query->set('dg_exact_product_search', true); } }); add_filter('posts_join', function ($join, $query) { global $wpdb; if ($query->get('dg_exact_product_search')) { $join .= " LEFT JOIN {$wpdb->postmeta} AS dg_sku ON ({$wpdb->posts}.ID = dg_sku.post_id AND dg_sku.meta_key = '_sku') "; } return $join; }, 10, 2); add_filter('posts_where', function ($where, $query) { global $wpdb; if (!$query->get('dg_exact_product_search')) { return $where; } $search = trim($query->get('s')); if ($search === '') { return $where; } $terms = preg_split('/\s+/', $search); foreach ($terms as $term) { $term = trim($term); if (strlen($term) < 2) { continue; } $like = '%' . $wpdb->esc_like($term) . '%'; $where .= $wpdb->prepare( " AND ( {$wpdb->posts}.post_title LIKE %s OR dg_sku.meta_value LIKE %s ) ", $like, $like ); } return $where; }, 10, 2); add_filter('posts_distinct', function ($distinct, $query) { if ($query->get('dg_exact_product_search')) { return 'DISTINCT'; } return $distinct; }, 10, 2);
Compare list is empty.
No account yet?
Create an Account