Bp_Search_Posts:: sql (search_term美元only_totalrow_count美元

描述

文件:bp-search /类/ class-bp-search-posts.php

公共函数的sql (search_term, only_totalrow_count美元= false){/ *联合查询一个例子  :- ----------------------------------------------------- ( 选择wp_posts。Id, 'posts'作为类型,wp_posts。post_title LIKE '%ho%' AS相关性,wp_posts。post_date as entry_date FROM wp_posts WHERE 1=1 AND (((wp_posts.))post_title LIKE '%ho%') OR (wp_posts. txt . txt)post_content LIKE '%ho%'))和wp_posts。post_type IN ('post', 'page', 'attachment') AND (wp_posts. txt . txt)post_status = 'publish' OR wp_posts. post_status = 'publish' OR wp_posts. post_status = 'publish'post_author = 1 AND wp_posts. post_author = 1post_status = '私人 ' ) ) ---------------------------------------------------- */ 全球wpdb美元;$ bp_prefix = bp_core_get_table_prefix ();数组$ query_placeholder = ();$sql = " SELECT ";if($only_totalrow_count){$sql .= " COUNT(DISTINCT id) "; "; } else { $sql .= " DISTINCT id , %s as type, post_title LIKE %s AS relevance, post_date as entry_date "; $query_placeholder[] = $this->search_type; $query_placeholder[] = '%'. $search_term .'%'; } $sql .= " FROM {$wpdb->posts} p "; /* ++++++++++++++++++++++++++++++++ * wp_posts table fields +++++++++++++++++++++++++++++++ */ $taxonomies = get_object_taxonomies( $this->pt_name ); foreach ( $taxonomies as $taxonomy ) { if ( bp_is_search_post_type_taxonomy_enable( $taxonomy, $this->pt_name ) ) { $tax[] = $taxonomy; } } //Tax query left join if ( ! empty( $tax ) ) { $sql .= " LEFT JOIN {$wpdb->term_relationships} r ON p.ID = r.object_id "; } //WHERE $sql .= " WHERE 1=1 AND ( p.post_title LIKE %s OR {$bp_prefix}bp_strip_tags(p.post_content) LIKE %s "; $query_placeholder[] = '%'. $search_term .'%'; $query_placeholder[] = '%'. $search_term .'%'; //Tax query if ( ! empty( $tax ) ) { $tax_in_arr = array_map( function( $t_name ) { return "'" . $t_name . "'"; }, $tax ); $tax_in = implode( ', ', $tax_in_arr ); $sql .= " OR r.term_taxonomy_id IN (SELECT tt.term_taxonomy_id FROM {$wpdb->term_taxonomy} tt INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id WHERE ( t.slug LIKE %s OR t.name LIKE %s ) AND tt.taxonomy IN ({$tax_in}) )"; $query_placeholder[] = '%'. $search_term .'%'; $query_placeholder[] = '%'. $search_term .'%'; } //Meta query if ( bp_is_search_post_type_meta_enable($this->pt_name) ) { $sql .= " OR p.ID IN (SELECT post_id FROM {$wpdb->postmeta} WHERE {$bp_prefix}bp_strip_tags(meta_value) LIKE %s )"; $query_placeholder[] = '%'. $search_term .'%'; } //Post should be publish $sql .= ") AND p.post_type = '{$this->pt_name}' AND p.post_status = 'publish' "; $sql = $wpdb->prepare( $sql, $query_placeholder ); return apply_filters( 'Bp_Search_Posts_sql', $sql, array( 'search_term' => $search_term, 'only_totalrow_count' => $only_totalrow_count, ) ); }

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队