Skip to content

Instantly share code, notes, and snippets.

@msaari
Last active February 26, 2017 04:10
Show Gist options
  • Save msaari/b6ae63960ce683c0aa3b8cdf23dfc43b to your computer and use it in GitHub Desktop.
Save msaari/b6ae63960ce683c0aa3b8cdf23dfc43b to your computer and use it in GitHub Desktop.
Relevanssi part number checker
function rlv_is_a_pn($candidate) {
$array = str_split($candidate);
$has_letters = false;
$has_numbers = false;
foreach ($array as $letter) {
if (is_numeric($letter)) {
$has_numbers = true;
}
else {
$has_letters = true;
}
if ($has_numbers && $has_letters) return true;
}
return $false;
}
add_filter('relevanssi_remove_punctuation', 'cut_search_to_6', 11);
function cut_search_to_6($a) {
if (rlv_is_a_pn($a)) {
$a = substr($a, 0, 6);
}
return $a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment