Image may be NSFW.
Clik here to view.
A couple of months ago I wrote about the Search Reloaded WordPress plugin, which sorts search results by relevance rather than by date.
Recently, SDK commented and said that she would like it if Search Reloaded also searched the comments.
So, 2 weeks ago when Stratos agreed to create plugins for reasonable requests, I requested that Search Reloaded be “tweaked” so it can also search comments. And Stratos did just that. You can read about it on his website.
The plugin will search posts and comments and list all of the posts that contain the search term in either the post or the comments. When I first tried it, I was confused because I thought the comments and the posts would be listed out. Stratos, however, set me straight and told me that would be way too complicated.
To test it I needed to think of a term that would be in the comments but not in an article. I then remembered that a nasty commenter called my readers sycophants and that as joke I called a regular reader the same thing in another article. And I knew that was much too large of a word for me to ever use in an actual article. So, search on sycophants and you will get two results (well, maybe three now with this article). One result will be a post and two will be the posts that have comments containing that term. Cool, huh?
The Search Reloaded plugin, however, doesn’t have a GPL or General Public License , so Stratos couldn’t redo the plugin and redistribute it but instead provided the code that would need to be edited in the plugin file.
So, here’s what you do. You’re going to have to edit the plugin file. If you aren’t comfortable with that you can ask me or Stratos for assistance.
- Go to Plugins > Plugin Editor
- Make a copy of the text or have a copy of the plugin available in case things go awry
- Look for the following block of code. If you copy it into a text editor with line numbering it starts at line 111.
$search_query = " SELECT posts.*, CASE WHEN posts.post_title REGEXP ‘$reg_one_present’ THEN 1 ELSE 0 END AS keyword_in_title, MATCH ( posts.post_title, posts.post_content ) AGAINST ( ‘" . addslashes($query_string) . "’ ) AS mysql_score FROM $wpdb->posts as posts WHERE posts.post_date_gmt <= ‘" . $now . "’" . ( ( defined(’sem_home_page_id’) && sem_home_page_id ) ? " AND posts.ID <> " . intval(sem_home_page_id) : "" ) . " AND posts.post_password = ” AND posts.post_status = ‘publish’ AND ( posts.post_title REGEXP ‘$reg_one_present’ OR posts.post_content REGEXP ‘$reg_one_present’ ) GROUP BY posts.ID ORDER BY keyword_in_title DESC, mysql_score DESC, posts.post_date DESC LIMIT " . intval($offset) . ", ". intval($posts_per_page);
- And replace with …
$search_query = " SELECT posts.*, CASE WHEN posts.post_title REGEXP ‘$reg_one_present’ THEN 1 ELSE 0 END AS keyword_in_title, MATCH ( posts.post_title, posts.post_content ) AGAINST ( ‘" . addslashes($query_string) . "’ ) AS mysql_score FROM $wpdb->posts as posts, $wpdb->comments as comments WHERE posts.post_date_gmt <= ‘" . $now . "’" . ( ( defined(’sem_home_page_id’) && sem_home_page_id ) ? " AND posts.ID <> " . intval(sem_home_page_id) : "" ) . " AND posts.post_password = ” AND posts.post_status = ‘publish’ AND posts.ID = comments.comment_post_ID AND ( posts.post_title REGEXP ‘$reg_one_present’ OR posts.post_content REGEXP ‘$reg_one_present’ OR comments.comment_content REGEXP ‘$reg_one_present’) GROUP BY posts.ID ORDER BY keyword_in_title DESC, mysql_score DESC, posts.post_date DESC LIMIT " . intval($offset) . ", ". intval($posts_per_page);
Now, I have totally stolen this code from Statos so please visit his site and check out the other WordPress plugins he has made.
Stratos hasn’t posted his services page yet but if you are looking to hire someone to develop a custom plugin for you, his contact information is on his About page.
photo credit: pygment_shots
The post WordPress Plugin Search Reloaded – Tweaked by Stratos appeared first on (Anti) Social Development.