Advertisement
Guest User

Better Search WP plugin Exclude Posts/Pages from Results

a guest
May 10th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. $sql = "SELECT ID, ";
  2.  
  3. $sql .= "(MATCH(post_title) AGAINST ('%s' ".$boolean_mode." ) * %d ) + ";
  4.  
  5. $sql .= "(MATCH(post_content) AGAINST ('%s' ".$boolean_mode.") * %d ) ";
  6.  
  7. $sql .= "AS score FROM ".$wpdb->posts." WHERE MATCH (post_title,post_content) AGAINST ('%s' ".$boolean_mode.") AND post_status = 'publish' ";
  8.  
  9. // Exclude custom post types from search results
  10. // Custom post type excluded here is "announcements"
  11. $sql .= "AND post_type != 'announcements' ";
  12.  
  13. $sql .= "AND ( ";
  14.  
  15. $multiple = false;
  16.  
  17. foreach ($post_types as $post_type) {
  18.  
  19. if ( $multiple ) $sql .= ' OR ';
  20.  
  21. $sql .= " post_type = '%s' ";
  22.  
  23. $multiple = true;
  24.  
  25. $args[] = $post_type; // Add the post types to the $args array
  26.  
  27. }
  28.  
  29. $sql .=" ) ";
  30.  
  31. // Exclude post IDs from search results
  32. // The post IDs are comma delimited
  33. $sql .= "AND ID NOT IN (100,203,400) ";
  34.  
  35. if ($bydate) {
  36.  
  37. $sql .= "ORDER BY post_date DESC ";
  38.  
  39. } else {
  40.  
  41. $sql .= "ORDER BY score DESC ";
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement