WC_Data_Store_WP::get_valid_search_terms()protectedWC 3.4.0

Check if the terms are suitable for searching.

Uses an array of stopwords (terms) that are excluded from the separate term matching when searching for posts. The list of English stopwords is the approximate search engines list, and is translatable.

Метод класса: WC_Data_Store_WP{}

Хуков нет.

Возвращает

Массив. Terms that are not stopwords.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_valid_search_terms( $terms );
$terms(массив) (обязательный)
Terms to check.

Список изменений

С версии 3.4.0 Введена.

Код WC_Data_Store_WP::get_valid_search_terms() WC 8.7.0

protected function get_valid_search_terms( $terms ) {
	$valid_terms = array();
	$stopwords   = $this->get_search_stopwords();

	foreach ( $terms as $term ) {
		// keep before/after spaces when term is for exact match, otherwise trim quotes and spaces.
		if ( preg_match( '/^".+"$/', $term ) ) {
			$term = trim( $term, "\"'" );
		} else {
			$term = trim( $term, "\"' " );
		}

		// Avoid single A-Z and single dashes.
		if ( empty( $term ) || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) ) {
			continue;
		}

		if ( in_array( wc_strtolower( $term ), $stopwords, true ) ) {
			continue;
		}

		$valid_terms[] = $term;
	}

	return $valid_terms;
}