I'm working on an older site with a million plugins that just can't handle SearchWP and trying to mimic some of that plugins functionality.
Things that ARE working:
- my search includes an ACF textarea field with a big chunk of content client's drop in it (a transcript)
- I'm able to create an excerpt from that ACF textarea field for search results
- I'm able to highlight the keyword in the search results
What's NOT working:
I'd like a way to output the part of the full contents of ACF textarea field that contains the keyword. Right now the excerpt is being created with
wp_trim_wordsbut always starts at the beginning. The highlighted keyword is snagged with the following code I found in another similar question on here:
$raw_content = get_field('transcript'); $trimmed_content = wp_trim_words($raw_content); $keys = implode('|', explode(' ', get_search_query())); $raw_content = preg_replace('/(' . $keys .')/iu', '<strong class="search-highlight">\0</strong>', $raw_content);
I don't have a preference for php or js.
$raw_content = get_field('transcript');with
$raw_content = .....;, add in a
$search_termvariable, and remove all references to ACF, you can both bring this question on-topic here, then make it offtopic again by turning it into a generic PHP question that can be asked on stackoverflow, and answered by 10x as many developers. You're heavily limiting your options by constricting your search to ACF, and more so by only looking for WordPress based solutions. Where the
$raw_contentgets its value from is irrelevant to your problem, and ACF is just there to confuse people