On a WordPress blog let’s we have an article with 3 paragraphs with the following content:
This is my first row.
This is my second row, wow.
This is my third row, wow.
Let’s I will execute a search based on the word “wow”. How can I resolve, so in the results will appear an excerpt or a content, basically this is a full paragraph (obviously longer then in our example), but I want to show up the first parapraph which has the searched term inside it, instead of the very first paragraph of the content without any search term inside of it.
Thank you.
You cannot out of the box.
What you can do, is parse the content using a DOM library once
wpautophas kicked in (e.g.add_filter('the_content', 'yourfunction', 15);), and testing paragraphs one by one until you find the word you need. (Or regexp-foo’ing your way to it, even if it’s highly unrecommended to do so.)I’m sure the WP core devs will be very happy if you contribute a patch once you’ve implemented it.