Trim the search result around the search word

A random thought: put the search string into an array ( with explode). Find the array position of the highlighted string. Count back xx for the start, and forward xx for the end. Extract those array values, then implode them back into a string. That would work for one searchresult word in the string. You’d … Read more

Template Page Content Made Searchable

By default WordPress cannot search in template content. You should import your content into the data base. The plugin HTML Import 2 will help here. Another option is a separate search engine with a parser that can read the complete HTML output. The plugin Search Unleashed for example supports Apache Lucene. That’s probably too much … Read more

How to show a random selection of posts from the search

This is easy to do using the pre_get_posts action hook to set the orderby to rand in the query, something like this: function random_search_result( $q ) { if ( is_search() && is_main_query() ) $q->set( ‘orderby’, ‘rand’); } add_action( ‘pre_get_posts’, ‘random_search_result’ );

SQL query to get adjacent posts from search query

Although this is possible, it really is not viable. I’ve done a lot of research on this subject, but could not find a straight forward answer I went and had a look at the WP_Query class for a possible solution, and I came to the conclusion that what I was trying to accomplish would not … Read more

Strange Search Queries in Apache Status

I’m sure you’ve googled ‘khabarnaak’ – it’s a Pakistani talk show. It’s more likely to be an automated scraper trying to find content rather than an attack. The request does not look like it has been crafted for a WordPress site. Two ways to stop it are: Block the IPs making the request. Add ‘Deny … Read more

Sitelinks Search Box in Google and urlencoded search string

I can confirm that url-decoding the search query is the correct approach. In fact, it is done in WordPress core for the search parameter of WP_Query but not when the search string is from a $_GET request as it is seen in WP_Query::parse_search() method, wp-includes/query.php#L2061 (WP 4.2.2): if ( empty( $_GET[‘s’] ) && $this->is_main_query() ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)