In WordPress, when searching, the announcement of the record is displayed, in which there is a search query. Is it possible to somehow display not the announcement of the record, but the part of the text that includes the search query?

  • And what is a piece of text? Is it 200 characters to the highest point from the search entry? And after? Then you need php tools to read the entire content, find pruning and output. - ffeynmann
  • Yes exactly. Only how can this be done using PHP? - Frontender
  • Isn't it easier to use ready-made solution? - LowSkiII
  • Is there any ready-made solution? Standard search does not allow to implement as needed. - Frontender

1 answer 1

WordPress themes usually output search results using the search.php template. In the standard twentysixteen theme, this template \ wp-content \ themes \ twentysixteen \ search.php also causes \ wp-content \ themes \ twentysixteen \ template-parts \ content-search.php

You can edit this template in the part where the function excerpt is called and put your code there, which receives the content of the post and does what it needs with it. A search query in the template code can be obtained as follows:

$search = $_GET['s']; 

In other topics it works the same way.