1

I am attempting to customise a search result page to display a title and excerpt that contains the search query.

I am using the "Search everything" plugin for this, and I find that sometimes on a more obscure search query, the excerpt displayed in with get_the_excerpt(); does not contain the search query, as it appears further into the post.

My question is: Can I customise the start index of my excerpt to ensure the search result is within the excerpt, for example:

"... here the except will lead in so find our search query and then lead out again..."

I am working on a site that was built by a colleague who no longer works for the company, so I can't ask him questions, and I would also like to avoid messing around in functions.php and any core functionality, as I don't want to break anything in another section of the site. (as well as my wordpress knowledge is almost non-existent) so I would prefer some kind of page-local based solution.

Thanks

  • 1
    Are your search results returning the Excerpt field's content? If so, you'll probably have to look into writing some code, unfortunately. To test if this is the case, find a post in your search results on the backend and see if the text in the results matches the text in the excerpt field. – phatskat Oct 5 '15 at 13:50
  • Just to add to @phatskat 's comment it's a tricky problem and you'll almost certainly have to get your hands dirty with "functions.php" and the template "content-search.php" and perhaps elsewhere depending on your theme ... I've code I use I could post if you're interested... – bonger Oct 5 '15 at 14:10
0

The Search Everything plugin supports "Search Highlighting" in the results page which should produce the results you are looking for.

We have no way of knowing how customized the search results page is in your specific project though. You may find that you are fighting an up hill battle until you (or someone on your team) can dive into the PHP to determine what's going on in there.

  • Thanks for the answer here, In the end I wrote my own function to sort it all out and perform underlining (I turned off the search everything highlighting as it was only highlighting the title) I will accept this as answered, as its the only answer to the question. Cheers. – Aphire Oct 6 '15 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.