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 ) );
}
请教达人。
...全文
100 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
moliu 2015-11-21
  • 打赏
  • 举报
回复
$clause, $parent_query  和 nested query 嵌套查询相对应的  在wordpress 里,parent query 到底是哪些?有些迷糊
xuzuning 2015-11-20
  • 打赏
  • 举报
回复
$parent_query Parent query of $clause 父查询子句 find_compatible_table_alias 查找兼容表别名 对于具体解释,你就不能找个中文的教程看看吗?
moliu 2015-11-20
  • 打赏
  • 举报
回复
  关于函数 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'.
moliu 2015-11-19
  • 打赏
  • 举报
回复
$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 ) 中,有上面的代码。能否以此为例讲一下?

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧