got a solution with https://stackoverflow.com/questions/15737408/php-find-all-occurrences-of-a-substring-in-a-string
$lastPos = 0;
$positions = array();
if($pos==''){}
else{
while (($lastPos = strpos($content, $findme, $lastPos))!== false){
$positions[] = $lastPos;
$lastPos = $lastPos + strlen($findme);
}
// Displays
foreach ($positions as $eachPos){
$pos = $eachPos;
$exctractAfterQuery = substr($content,($pos+strlen($findme) ),40);
$exctractBeforeQuery = substr($content,$pos-40,40);
$newContent .= "[...".$exctractBeforeQuery.'<strong class="search-highlight">'.$findme."</strong>".$exctractAfterQuery."...]<br>";
}
}
It works well and no need a plugin. hope this help someone
Related Posts:
- Multiple keyword search
- Is there any advantage of using default WordPress Search instead of creating a custom one?
- Cutom wp_query for geolocation search, pagination not working
- How to extend WP_query to a specific table?
- Display the search results like the original pages
- Add to search posts query array with post IDS which will appear first
- Post_count only shows the number of results per page
- WP Query where title begins with a specific letter
- Search multiple custom fields by using meta_query
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Tracing the life of a query
- Pagination not working for Custom search form & custom result template
- Pagination broken when merging search results with additional WP_Query
- How to search by title or tags exclusively?
- WordPress search exact match
- Using next/previous_posts_link with customised search
- WordPress custom search form with pre_get_posts not work
- Show default content if custom WP_Query has no posts
- Add custom search results to main WP search [duplicate]
- WP Query search for attachments and their exact title
- wp_query ‘s’ parameter does not work with custom post type
- Modifying the Search Results
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Creating a custom search for a specific post type
- Custom Search Result Page displaying only 1 result.
- showing all search result in one template
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Search pages that are a child of the current page
- Include tags in WP_Query
- Custom Search Not Consistent with Results
- Use post object from first query in second query
- Editing the default wordpress search
- How to use wp_query to post count by search term > group post count by date > convert to json. (ex. result 12-21-2020 – 343)
- Multiple Search Terms WP_Query
- Query to get siblings and parent page
- Extend product search with meta in WooCommerce
- WP Query Args – Title or Taxonomy Value
- Search by post id in a specific page then auto-redirect to searched post
- Search for “2nd” also returns “22nd” in wp_query
- Include data from custom table in WP_Query
- Categorising search results based on Custom Fields
- echo a specific meta_key queried through a custom post
- WP Group posts by year(desc) > month(desc) > date(asc)
- Add filter post_where and passing post_type argument
- using pre_get_posts for search results not found
- wp_query search not taking keywords with together for multiple words
- Wildcard search in WP Query
- Search Page Returns Nothing
- How to avoid bypass of search bar rules?
- Hide products in uncategorized category from search results
- How do you determine if a result in a search query is a post or a page?
- wp_query show all values
- change posts_orderby of the callback wp_query?
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- Orderby two meta fields not working
- Ignore image urls in wp_query search
- Search.php – return number of results but cannot loop through
- Adding pagination to sub-wp_query within a singular post page
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Where is this query?
- $wp_query->found_posts not returning correct value
- How to search by slug and old slug in single API
- WordPress search WP_Query to cover multiple post types and their custom fields?
- How to prevent WP_Query from filtering on ‘s’ but keep ‘s’ for other purposes?
- Add dynamic search to paginated WP_Query
- Multiple WP_Query args combinations according to post type
- Categories In English version showing not canonical URL, instead shows query search result
- Filter admin ajax data by url query
- Custom order revolution sliders post base slides as inserted in Specific Posts List field
- How to use jQuery validation to set the search bar to accept only a specific input?
- How to debug none working search query?
- Search with WP_Query, but ignore href URLs in anchor tags?
- WordPress search page pagination displaying but not functional
- Woocomerce – Order products by float attribute in archive pages
- Limit default Search query to post_title
- Multiple values in WP_Query : category__and
- Order & Orderby clause not working with custom query
- How can I modify standard search query to include also ACF custom fields values?
- How to make the default WordPress search return borader results
- WordPress WP_Query offset parameter not working with search parameter
- WordPress WP_Query Array Custom search via taxonomies
- Need help setting up a search form for wordpress [duplicate]
- Get the type of an advanced custom field (ACF) in a WP_Query loop [closed]
- Manipulating a query
- Custom search: Search posts but display parent page in results
- Query posts by custom fields
- Searching in specific custom post type
- Search (Custom Form, Custom Search Result)
- Help with showing text when something is entered in my search bar
- shortcode with $atts with strange results
- Filtering product search results using tags
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- Search query alteration not working for meta values
- Search results stuck on page 1
- Custom Taxonomy in custom REST API search
- Advanced Search – Is this possible?
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- AJAX multiple search boxes not merging with array merge