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
- Rewrite URL custom search query
- 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
- Search posts missing a particular custom field
- How do I get my custom query to work with search results after the first page?
- Modify Search Query if original Query gave no results
- Exclude posts with specific metadata from search?
- Include post content of linked posts in search
- Replacing search results with custom external query
- Prevent author bio page from showing in search results
- How do I amend wp_query before it is run/executed?
- wp_query search not taking keywords with together for multiple words
- Wildcard search in WP Query
- Get a list of posts by specific category
- WordPress Custom Search Form Displaying Unexpected Results
- Search Page Returns Nothing
- Redirect Search to Form When No Product Results Are Found
- How to properly use AND / OR in custom search
- How to avoid bypass of search bar rules?
- Hide products in uncategorized category from search results
- How to order posts on each different category?
- Issues with search after added meta_query
- How do you determine if a result in a search query is a post or a page?
- Slow Query On Search
- Sorting search results with custom dropdown
- How To Keep Search Title the same on paged Results
- Get specific ACF key and value from all posts – no access to DB
- 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?
- How to restrict search on a certain page to only return results against custom taxonomies?
- Filter out a meta key in the Search results page with two CPT
- Query by key or author
- Orderby two meta fields not working
- Custom wp_query – I’m getting ‘all’ post, not the specific post in the query
- Ignore image urls in wp_query search
- meta_query with array as value with multiple arrays
- Search.php – return number of results but cannot loop through
- Can I make a search query which includes a space?
- Adding pagination to sub-wp_query within a singular post page
- How to filter a static post page with ajax and $wp_query
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- How to make a query returning pages from multiple parents
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Where is this query?
- Searching not only by post name but also category
- $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?
- My combination of ‘post_type’ and ‘tax_query’ not working?
- How to separate two columns from one content on a page template?
- How to prevent WP_Query from filtering on ‘s’ but keep ‘s’ for other purposes?
- Block internal search queries with pre_get_posts and regex rules
- Add dynamic search to paginated WP_Query
- How to make the WP query search for the “s” arg in other places too
- Search Exact on WordPress – Relevannsi Solution Not Working
- Excluding posts from search results page with meta query not working
- Pagination repeating posts on search results
- I have problems with the search query using multiple post types
- WP_Query no result if keyword contains number
- Multiple WP_Query args combinations according to post type
- Categories In English version showing not canonical URL, instead shows query search result
- How to use wp query in my custom page without including header and footer in wordpress
- Filter admin ajax data by url query
- Custom order revolution sliders post base slides as inserted in Specific Posts List field
- WP Query for all events prior to current date
- How to use jQuery validation to set the search bar to accept only a specific input?
- Display Search Results by tag_ID in my search.php
- How to debug none working search query?
- Multi line of $wpdb->query just run 1 time and end the loop right after
- getting posts by tags
- Custom Post Type WP_Query with filters and search
- 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
- Search has query that will return no results
- WP Query – Search in title or author_name
- Limit default Search query to post_title
- Get posts by similar names and categories
- Multiple values in WP_Query : category__and
- Logging search queries for logged-in users
- How to show terms from another taxonomy
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- Order & Orderby clause not working with custom query
- How to set up pagination for a custom loop on a global template (author.php, tag.php, archive.php?)
- How can I modify standard search query to include also ACF custom fields values?
- A very strange problem with search query
- Custom query using WP_Query is not working
- Search format not matching taxonomy query
- How to make the default WordPress search return borader results
- Search Functionality broken by the wp 4.2 update
- WordPress WP_Query offset parameter not working with search parameter
- Custom search (wp query by custom fields)