优化需要20秒钟执行的Wocommerce Ajax产品过滤器插件查询

时间:2019-12-10 08:52:15

标签: wordpress woocommerce

下面是查询

$query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count, GROUP_CONCAT(DISTINCT {$wpdb->posts}.ID SEPARATOR ',') as PID, terms.term_id as term_count_id";

$query['from']   = "FROM {$wpdb->posts}";
$query['join']   = "
                     INNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id
                     INNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id )
                     INNER JOIN {$wpdb->terms} AS terms USING( term_id )
                        " . $tax_query_sql['join'] . $meta_query_sql['join'];
$query['where']   = "
                        WHERE {$wpdb->posts}.post_type IN ( 'product' )
                        AND " . br_select_post_status() . "
                        " . $tax_query_sql['where'] . $meta_query_sql['where'] . "
                        AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
                    "; 

0 个答案:

没有答案