Bp_Search_bbPress_Forums:: sql (search_term美元,only_totalrow_count美元=假)
描述
源
文件:bp-search /类/ class-bp-search-bbpress-forums.php
函数sql($search_term, $only_totalrow_count=false){global $wpdb;$ bp_prefix = bp_core_get_table_prefix ();数组$ query_placeholder = ();if($only_totalrow_count){$columns = " COUNT(DISTINCT id) ";”;} else {$ columns = " DISTINCT id, '{$this->type}' as type, post_title LIKE %s as relevance, post_date as entry_date ";美元query_placeholder[] =‘%’。search_term美元。‘%’;} $from = "{$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm ON pm. "post_id = p.ID AND pm. post_id = p.ID;meta_key = _bbp_group_ids”; $where = array(); $where[] = "1=1"; $where[] = "(post_title LIKE %s OR {$bp_prefix}bp_strip_tags(post_content) LIKE %s)"; $where[] = "post_type = '{$this->type}'"; if ( current_user_can( 'read_hidden_forums' ) ) { $post_status = [ 'publish', 'private', 'hidden' ]; } elseif ( current_user_can( 'read_private_forums' ) ) { $post_status = [ 'publish', 'private' ]; } else { $post_status = [ 'publish' ]; } $in = '0'; if ( ! bp_is_search_groups_enable() ) { $group_memberships = ''; if ( bp_is_active( 'groups' ) ) { $group_memberships = bp_get_user_groups( get_current_user_id(), array( 'is_admin' => null, 'is_mod' => null, ) ); } if ( ! empty( $group_memberships ) ) { $in = array_reduce( array_keys( $group_memberships ), function ( $carry, $group_id ) { return $carry . ',\'' . maybe_serialize( [ $group_id ] ) . '\''; } ); } } else { $where[] = 'pm.post_id IS NULL'; } $where[] = '( post_status IN (\'' . join( '\',\'', $post_status ) . '\') OR pm.meta_value IN ('. trim( $in, ',' ) .') )'; $query_placeholder[] = '%'. $search_term .'%'; $query_placeholder[] = '%'. $search_term .'%'; $sql = 'SELECT '. $columns . ' FROM ' . $from .' WHERE ' . implode( ' AND ', $where ); $query = $wpdb->prepare( $sql, $query_placeholder ); return apply_filters( 'Bp_Search_Forums_sql', $query, array( 'search_term' => $search_term, 'only_totalrow_count' => $only_totalrow_count, ) ); }