BBoss_Global_Search_Forums

BuddyPress Global Search - search forums **************************************.

Defined (1)

The class is defined in the following location(s).

/includes/search-types/class.BBoss_Global_Search_Forums.php  
  1. class BBoss_Global_Search_Forums extends BBoss_Global_Search_Type { 
  2. private $type = 'forums'; 
  3.  
  4. /** 
  5. * Insures that only one instance of Class exists in memory at any 
  6. * one time. Also prevents needing to define globals all over the place. 
  7. * @since 1.0.0 
  8. *  
  9. * @return object BBoss_Global_Search_Forums 
  10. */ 
  11. public static function instance() { 
  12. // Store the instance locally to avoid private static replication 
  13. static $instance = null; 
  14.  
  15. // Only run these methods if they haven't been run previously 
  16. if (null === $instance) { 
  17. $instance = new BBoss_Global_Search_Forums(); 
  18.  
  19. // Always return the instance 
  20. return $instance; 
  21.  
  22. /** 
  23. * A dummy constructor to prevent this class from being loaded more than once. 
  24. * @since 1.0.0 
  25. */ 
  26. private function __construct() { /** Do nothing here */ 
  27. function sql( $search_term, $only_totalrow_count=false ) { 
  28. global $wpdb; 
  29. $query_placeholder = array(); 
  30.  
  31. $sql = " SELECT "; 
  32.  
  33. if( $only_totalrow_count ) { 
  34. $sql .= " COUNT( DISTINCT id ) "; 
  35. } else { 
  36. $sql .= " DISTINCT id , 'forums' as type, post_title LIKE '%%%s%%' AS relevance, post_date as entry_date "; 
  37. $query_placeholder[] = $search_term; 
  38.  
  39. $sql .= " FROM  
  40. {$wpdb->prefix}posts  
  41. WHERE  
  42. 1=1  
  43. AND ( 
  44. (post_title LIKE '%%%s%%')  
  45. OR (post_content LIKE '%%%s%%') 
  46. )  
  47. AND post_type IN ( 'forum', 'topic', 'reply' )  
  48. AND post_status = 'publish'  
  49. "; 
  50. $query_placeholder[] = $search_term; 
  51. $query_placeholder[] = $search_term; 
  52. $sql = $wpdb->prepare( $sql, $query_placeholder ); 
  53.  
  54. return apply_filters(  
  55. 'BBoss_Global_Search_Forums_sql',  
  56. $sql,  
  57. array(  
  58. 'search_term' => $search_term,  
  59. 'only_totalrow_count' => $only_totalrow_count,  
  60. )  
  61. ); 
  62.  
  63. protected function generate_html( $template_type='' ) { 
  64. $post_ids = array(); 
  65. foreach( $this->search_results['items'] as $item_id=>$item_html ) { 
  66. $post_ids[] = $item_id; 
  67.  
  68. //now we have all the posts 
  69. //lets do a wp_query and generate html for all posts 
  70. $qry = new WP_Query( array( 'post_type' =>array( 'forum', 'topic', 'reply' ), 'post__in'=>$post_ids, 'posts_per_page'=> -1 ) ); 
  71. if( $qry->have_posts() ) { 
  72. while( $qry->have_posts() ) { 
  73. $qry->the_post(); 
  74.  
  75. /** 
  76. * The following will try to load loop/forum.php, loop/topic.php loop/reply.php(if reply is included). 
  77. *  
  78. */ 
  79. $result_item = array( 
  80. 'id' => get_the_ID(),  
  81. 'type' => $this->type,  
  82. 'title' => get_the_title(),  
  83. 'html' => buddyboss_global_search_buffer_template_part( 'loop/' . get_post_type(), $template_type, false ),  
  84. ); 
  85.  
  86. $this->search_results['items'][get_the_ID()] = $result_item; 
  87. wp_reset_postdata(); 
  88.