wordpress 的 taxonomy.php 源码中,有 
function find_compatible_table_alias( $clause, $parent_query )
参数说明:
@param array       $clause       Query clause.
 @param array       $parent_query Parent query of $clause.
 @return string|false Table alias if found, otherwise false
困惑我好久的问题是:何谓 parent query ?请教达人。
 附:源码
     protected function find_compatible_table_alias( $clause, $parent_query ) {
1164                 $alias = false;
1165
1166                 // Sanity check. Only IN queries use the JOIN syntax .
1167                 if ( ! isset( $clause['operator'] ) || 'IN' !== $clause['operator'] ) {
1168                         return $alias;
1169                 }
1170
1171                 // Since we're only checking IN queries, we're only concerned with OR relations.
1172                 if ( ! isset( $parent_query['relation'] ) || 'OR' !== $parent_query['relation'] ) {
1173                         return $alias;
1174                 }
1175
1176                 $compatible_operators = array( 'IN' );
1177
1178                 foreach ( $parent_query as $sibling ) {
1179                         if ( ! is_array( $sibling ) || ! $this->is_first_order_clause( $sibling ) ) {
1180                                 continue;
1181                         }
1182
1183                         if ( empty( $sibling['alias'] ) || empty( $sibling['operator'] ) ) {
1184                                 continue;
1185                         }
1186
1187                         // The sibling must both have compatible operator to share its alias.
1188                         if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
1189                                 $alias = $sibling['alias'];
1190                                 break;
1191                         }
1192                 }
1193
1194                 return $alias;
1195         }
  
  何谓 first_order_clause?
Determine whether a clause is first-order
   protected static function is_first_order_clause( $query ) {
                return is_array( $query ) && ( empty( $query ) || array_key_exists( 'terms', $query ) || array_key_exists( 'taxonomy', $query ) || array_key_exists( 'include_children', $query ) || array_key_exists( 'field', $query ) || array_key_exists( 'operator', $query ) );
        }
请教达人。

解决方案 »

  1.   

     $terms = implode( ",", $query['terms'] );
      $terms = $wpdb->get_col( "
                                             SELECT $wpdb->term_taxonomy.$resulting_field
                                                           FROM $wpdb->term_taxonomy
                                            INNER JOIN $wpdb->terms USING (term_id)
                                            WHERE taxonomy = '{$query['taxonomy']}'
                                            AND $wpdb->terms.{$query['field']} IN ($terms)
    在 transform_query( &$query, $resulting_field ) 中,有上面的代码。能否以此为例讲一下?
      

  2.   


    关于函数 find_compatible_table_alias( $clause, $parent_query ) 有这样的
    说明,哪位达人解释一下?谢谢
    Identify an existing table alias that is compatible with the current query clause.          *
          * We avoid unnecessary table joins by allowing each clause to look for
             * an existing table alias that is compatible with the query that it
             * needs to perform.
             *
             * An existing alias is compatible if (a) it is a sibling of `$clause`
             * (ie, it's under the scope of the same relation), and (b) the combination
             * of operator and relation between the clauses allows for a shared table
             * join. In the case of WP_Tax_Query, this only applies to 'IN'
             * clauses that are connected by the relation 'OR'.
      

  3.   

    $parent_query Parent query of $clause
    父查询子句find_compatible_table_alias 查找兼容表别名对于具体解释,你就不能找个中文的教程看看吗?
      

  4.   

     $clause, $parent_query  和 nested query 嵌套查询相对应的
     在wordpress 里,parent query 到底是哪些?有些迷糊