Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › the option does not work › Reply To: the option does not work
January 8, 2019 at 1:40 pm
#20681
Keymaster
Hi,
Try this modified version of the code. Enter the keywords to be replaced to the $words variable, comma separated.
add_filter('asp_results', 'asp_remove_first_n_characters');
function asp_remove_first_n_characters($results) {
$remove = 200; // Enter the length to cut
$words = 'word1, word2'; // Enter the words to replace
// Replace the keywords
$words = explode(',', $words);
foreach ( $words as $wk => &$word ) {
$word = trim($word);
if ( $word != '' )
unset($words[$wk]);
}
if ( count($words) > 0 ) {
// implode() words into a pipe-delimited string
$pattern = "/\b(" . implode("|", $words) . ")\b/i";
foreach ($results as $k => &$r) {
$r->content = preg_replace($pattern, "", $r->content);
}
}
// Trim the length
foreach ($results as $k => &$r) {
if ( strlen($r->content) > $remove )
$r->content = substr($r->content, $remove);
}
return $results;
}