theguess
Новичок
Доброго времени суток, уважаемые форумчане.
интересует вопрос по поиску для данной платформы.
на данный момент стоит WR Live Search.
к примеру товар:
БЛОК ДОЗИРОВОЧНЫЙ ЯМЗ-650. CUMMINS ZME (АКТУАТОР) BOSCH
Артикул: 0 928 400 617
по артикулу и названию он ищет нормально.
вопрос:
как заставить его искать вводя часть артикла и часть названия?
например ЯМЗ 617
интересует вопрос по поиску для данной платформы.
на данный момент стоит WR Live Search.
к примеру товар:
БЛОК ДОЗИРОВОЧНЫЙ ЯМЗ-650. CUMMINS ZME (АКТУАТОР) BOSCH
Артикул: 0 928 400 617
по артикулу и названию он ищет нормально.
вопрос:
как заставить его искать вводя часть артикла и часть названия?
например ЯМЗ 617
// Find keyword in title.
if ( $data['search_in']['title'] == 1 ) {
// Convert HTML tag and shortcode to space.
$content_search = preg_replace( '/\\[[^\\]]*\\]|<[^>]*>/', ' ', $product->post_title );
// Find keyword.
$position_keyword = stripos( $content_search, $data['keyword'] );
if ( $position_keyword !== false && $position_keyword + strlen( $data['keyword'] ) < strlen( $content_search ) ) {
// Get suggestion of keyword in content.
$return_data['suggestion'] = self::get_suggestion( $content_search, $data['keyword'] );
break;
}
}
// Find keyword in description.
if ( $data['search_in']['description'] == 1 && ! isset( $return_data['suggestion'] ) ) {
// Convert HTML tag and shortcode to space.
$content_search = preg_replace( '/\\[[^\\]]*\\]|<[^>]*>/', ' ', $product->post_excerpt );
// Find keyword.
$position_keyword = stripos( $content_search, $data['keyword'] );
if ( $position_keyword !== false && $position_keyword + strlen( $data['keyword'] ) < strlen( $content_search ) ) {
// Get suggestion of keyword in content.
$return_data['suggestion'] = self::get_suggestion( $content_search, $data['keyword'] );
break;
}
}
// Find keyword in content.
if ( $data['search_in']['content'] == 1 && ! isset( $return_data['suggestion'] ) ) {
// Convert HTML tag and shortcode to space.
$content_search = preg_replace( '/\\[[^\\]]*\\]|<[^>]*>/', ' ', $product->post_content );
// Find keyword.
$position_keyword = stripos( $content_search, $data['keyword'] );
if ( $position_keyword !== false && $position_keyword + strlen( $data['keyword'] ) < strlen( $content_search ) ) {
// Get suggestion of keyword in content.
$return_data['suggestion'] = self::get_suggestion( $content_search, $data['keyword'] );
break;
}
}
// Find keyword in sku.
if ( $data['search_in']['sku'] == 1 && ! isset( $return_data['suggestion'] ) ) {
// Convert HTML tag and shortcode to space.
$content_search = preg_replace( '/\\[[^\\]]*\\]|<[^>]*>/', ' ', $product->wr_sku );
// Find keyword.
$position_keyword = stripos( $content_search, $data['keyword'] );
if ( $position_keyword !== false && $position_keyword + strlen( $data['keyword'] ) < strlen( $content_search ) ) {
// Get suggestion of keyword in content.
$return_data['suggestion'] = self::get_suggestion( $content_search, $data['keyword'] );
break;
if ( $data['search_in']['title'] == 1 ) {
// Convert HTML tag and shortcode to space.
$content_search = preg_replace( '/\\[[^\\]]*\\]|<[^>]*>/', ' ', $product->post_title );
// Find keyword.
$position_keyword = stripos( $content_search, $data['keyword'] );
if ( $position_keyword !== false && $position_keyword + strlen( $data['keyword'] ) < strlen( $content_search ) ) {
// Get suggestion of keyword in content.
$return_data['suggestion'] = self::get_suggestion( $content_search, $data['keyword'] );
break;
}
}
// Find keyword in description.
if ( $data['search_in']['description'] == 1 && ! isset( $return_data['suggestion'] ) ) {
// Convert HTML tag and shortcode to space.
$content_search = preg_replace( '/\\[[^\\]]*\\]|<[^>]*>/', ' ', $product->post_excerpt );
// Find keyword.
$position_keyword = stripos( $content_search, $data['keyword'] );
if ( $position_keyword !== false && $position_keyword + strlen( $data['keyword'] ) < strlen( $content_search ) ) {
// Get suggestion of keyword in content.
$return_data['suggestion'] = self::get_suggestion( $content_search, $data['keyword'] );
break;
}
}
// Find keyword in content.
if ( $data['search_in']['content'] == 1 && ! isset( $return_data['suggestion'] ) ) {
// Convert HTML tag and shortcode to space.
$content_search = preg_replace( '/\\[[^\\]]*\\]|<[^>]*>/', ' ', $product->post_content );
// Find keyword.
$position_keyword = stripos( $content_search, $data['keyword'] );
if ( $position_keyword !== false && $position_keyword + strlen( $data['keyword'] ) < strlen( $content_search ) ) {
// Get suggestion of keyword in content.
$return_data['suggestion'] = self::get_suggestion( $content_search, $data['keyword'] );
break;
}
}
// Find keyword in sku.
if ( $data['search_in']['sku'] == 1 && ! isset( $return_data['suggestion'] ) ) {
// Convert HTML tag and shortcode to space.
$content_search = preg_replace( '/\\[[^\\]]*\\]|<[^>]*>/', ' ', $product->wr_sku );
// Find keyword.
$position_keyword = stripos( $content_search, $data['keyword'] );
if ( $position_keyword !== false && $position_keyword + strlen( $data['keyword'] ) < strlen( $content_search ) ) {
// Get suggestion of keyword in content.
$return_data['suggestion'] = self::get_suggestion( $content_search, $data['keyword'] );
break;
public static function posts_where( $where ) {
global $wpdb, $wr_live_search_settings;
// Prepare search coverages.
$columns = array();
if ( isset( $wr_live_search_settings['search_in']['title'] ) && $wr_live_search_settings['search_in']['title'] == 1 ) {
$columns[] = ' ' . $wpdb->posts . '.post_title LIKE "%' . sanitize_text_field( $wr_live_search_settings['keyword'] ) . '%" ';
}
if ( isset( $wr_live_search_settings['search_in']['description'] ) && $wr_live_search_settings['search_in']['description'] == 1 ) {
$columns[] = ' ' . $wpdb->posts . '.post_excerpt LIKE "%' . sanitize_text_field( $wr_live_search_settings['keyword'] ) . '%" ';
}
if ( isset( $wr_live_search_settings['search_in']['content'] ) && $wr_live_search_settings['search_in']['content'] == 1 ) {
$columns[] = ' ' . $wpdb->posts . '.post_content LIKE "%' . sanitize_text_field( $wr_live_search_settings['keyword'] ) . '%" ';
}
if ( isset( $wr_live_search_settings['search_in']['sku'] ) && $wr_live_search_settings['search_in']['sku'] == 1 ) {
$columns[] = '( ' . $wpdb->postmeta . '.meta_key = "_sku" AND ' . $wpdb->postmeta . '.meta_value LIKE "%' . sanitize_text_field( $wr_live_search_settings['keyword'] ) . '%" )';
}
if ( count( $columns ) ) {
$where .= ' AND ( ' . implode( ' OR ', $columns ) . ' ) ';
}
return $where;
}
global $wpdb, $wr_live_search_settings;
// Prepare search coverages.
$columns = array();
if ( isset( $wr_live_search_settings['search_in']['title'] ) && $wr_live_search_settings['search_in']['title'] == 1 ) {
$columns[] = ' ' . $wpdb->posts . '.post_title LIKE "%' . sanitize_text_field( $wr_live_search_settings['keyword'] ) . '%" ';
}
if ( isset( $wr_live_search_settings['search_in']['description'] ) && $wr_live_search_settings['search_in']['description'] == 1 ) {
$columns[] = ' ' . $wpdb->posts . '.post_excerpt LIKE "%' . sanitize_text_field( $wr_live_search_settings['keyword'] ) . '%" ';
}
if ( isset( $wr_live_search_settings['search_in']['content'] ) && $wr_live_search_settings['search_in']['content'] == 1 ) {
$columns[] = ' ' . $wpdb->posts . '.post_content LIKE "%' . sanitize_text_field( $wr_live_search_settings['keyword'] ) . '%" ';
}
if ( isset( $wr_live_search_settings['search_in']['sku'] ) && $wr_live_search_settings['search_in']['sku'] == 1 ) {
$columns[] = '( ' . $wpdb->postmeta . '.meta_key = "_sku" AND ' . $wpdb->postmeta . '.meta_value LIKE "%' . sanitize_text_field( $wr_live_search_settings['keyword'] ) . '%" )';
}
if ( count( $columns ) ) {
$where .= ' AND ( ' . implode( ' OR ', $columns ) . ' ) ';
}
return $where;
}
Последнее редактирование: