Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a membership site where I am using Wishlist membership plugin. There are few Courses for which the user signed up and after signing up, they can get access to different modules and their corresponding lessons. All these lessons have multiple videos, files and pdfs attached to them via custom meta boxes( values are getting stored as serialized array in wp_postmeta table ). Moreover, each user can add his/her notes for each specific lessons( values are getting stored in a custom notes table ).

Now, I have to add Search feature on my site which should search for the following things:

  1. Post Content
  2. Post Comments
  3. Custom Meta boxes which consists of different video links, excel file links and pdfs links.
  4. Notes which user adds
  5. Spoken words in Videos

I have tried implementing Relevanssi Pro Search plugin for this since it searches values for custom meta fields as well. But, the result is not satisfactory at all.

Can anyone please suggest some good search plugin for this or do I need to go for some custom search solution for this?

share|improve this question
1  
While "recommend a plugin" is technically off-topic, I have found the issue of "We need more control over WordPress search" to be very problematic. As for the spoken words in videos, that seems impossible without a transcript. –  GhostToast Aug 27 '13 at 14:16
    
Thanks for your reply. You are right regarding spoken words. We definitely need transcripts for them. But, is there a way to implement search for the rest of the points? –  swtshweta Aug 27 '13 at 14:21

1 Answer 1

There is no easy way to do this without modifying the main search query that was generated by wordpress. I think you should go for posts_search & posts_join hook. They are located in wp-includes/query.php

Do a var_dump first to see what you are getting & modify accordingly. Here's some untested code i could put up right now to get you started.

add_filter('posts_search', 'search_function', 10, 2);
function search_function($search, $query) {
  if(is_admin() || !$query->is_main_query() || !$query->is_search)
    return; //determine if we are modifying the right query

  global $wpdb;
  $search_term = $query->get('s');
  $search = ' AND (';

  //point 1
  $search .= "($wpdb->posts.post_content LIKE '%$search_term%')";

  //need to add an OR between search conditions
  $search .= " OR ";

  //point 2
  $search .= "($wpdb->comments.comment_content LIKE '%$search_term%')";

  //need to add an OR between search conditions
  $search .= " OR ";

  //point 3
  $search .= "($wpdb->postmeta.meta_key = 'custom_field_key' AND $wpdb->postmeta.meta_value LIKE '%$search_term%')";

  //need to add an OR between search conditions
  $search .= " OR ";

  //point 4
  $search .= "({$wpdb->prefix}notes.text LIKE '%$search_term%')";

  //add the filter to join, sql will error out without joining the tables to the query
  add_filter('posts_join', 'join_tables');

  return $search . ') ';
}

function join_tables($join) {
  $join .= "JOIN $wpdb->comments ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)";
  $join .= "JOIN $wpdb->postmeta ON ($wpdb->postmeta.post_ID = $wpdb->posts.ID)";
  $join .= "JOIN {$wpdb->prefix}notes ON ({$wpdb->prefix}notes.post_ID = $wpdb->posts.ID)";
  return $join;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.