wordpress 中,何谓 parent query ?何谓 first_order_clause?
moliu 2015-11-19 04:54:06 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 ) );
}
请教达人。