Advertisement
Guest User

Untitled

a guest
Jan 29th, 2013
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. function change_wp_search_size($query) {
  2. if ( $query->is_search ) // Make sure it is a search page
  3. $query->query_vars['posts_per_page'] = 30; // Change 10 to the number of posts you would like to show
  4.  
  5. return $query; // Return our modified query variables
  6. }
  7. add_filter('pre_get_posts', 'change_wp_search_size'); // Hook our custom function onto the request filter
  8.  
  9.  
  10. function custom_search_where($where){
  11. global $wpdb;
  12. if (is_search())
  13. $where .= "OR (t.name LIKE '%".get_search_query()."%' AND {$wpdb->posts}.post_status = 'publish')";
  14. return $where;
  15. }
  16.  
  17. function custom_search_join($join){
  18. global $wpdb;
  19. if (is_search())
  20. $join .= "LEFT JOIN {$wpdb->term_relationships} tr ON {$wpdb->posts}.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id";
  21. return $join;
  22. }
  23.  
  24. function custom_search_groupby($groupby){
  25. global $wpdb;
  26.  
  27. // we need to group on post ID
  28. $groupby_id = "{$wpdb->posts}.ID";
  29. if(!is_search() || strpos($groupby, $groupby_id) !== false) return $groupby;
  30.  
  31. // groupby was empty, use ours
  32. if(!strlen(trim($groupby))) return $groupby_id;
  33.  
  34. // wasn't empty, append ours
  35. return $groupby.", ".$groupby_id;
  36. }
  37.  
  38. add_filter('posts_where','custom_search_where');
  39. add_filter('posts_join', 'custom_search_join');
  40. add_filter('posts_groupby', 'custom_search_groupby');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement