当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Meta_Query::has_or_relation方法代码示例

本文整理汇总了PHP中WP_Meta_Query::has_or_relation方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Meta_Query::has_or_relation方法的具体用法?PHP WP_Meta_Query::has_or_relation怎么用?PHP WP_Meta_Query::has_or_relation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Meta_Query的用法示例。


在下文中一共展示了WP_Meta_Query::has_or_relation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepare_query


//.........这里部分代码省略.........
         }
         $role__in_clauses = array('relation' => 'OR');
         if (!empty($role__in)) {
             foreach ($role__in as $role) {
                 $role__in_clauses[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => '"' . $role . '"', 'compare' => 'LIKE');
             }
             $role_queries[] = $role__in_clauses;
         }
         $role__not_in_clauses = array('relation' => 'AND');
         if (!empty($role__not_in)) {
             foreach ($role__not_in as $role) {
                 $role__not_in_clauses[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => '"' . $role . '"', 'compare' => 'NOT LIKE');
             }
             $role_queries[] = $role__not_in_clauses;
         }
         // If there are no specific roles named, make sure the user is a member of the site.
         if (empty($role_queries)) {
             $role_queries[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'compare' => 'EXISTS');
         }
         // Specify that role queries should be joined with AND.
         $role_queries['relation'] = 'AND';
         if (empty($this->meta_query->queries)) {
             $this->meta_query->queries = $role_queries;
         } else {
             // Append the cap query to the original queries and reparse the query.
             $this->meta_query->queries = array('relation' => 'AND', array($this->meta_query->queries, $role_queries));
         }
         $this->meta_query->parse_query_vars($this->meta_query->queries);
     }
     if (!empty($this->meta_query->queries)) {
         $clauses = $this->meta_query->get_sql('user', $wpdb->users, 'ID', $this);
         $this->query_from .= $clauses['join'];
         $this->query_where .= $clauses['where'];
         if ($this->meta_query->has_or_relation()) {
             $this->query_fields = 'DISTINCT ' . $this->query_fields;
         }
     }
     // sorting
     $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : '';
     $order = $this->parse_order($qv['order']);
     if (empty($qv['orderby'])) {
         // Default order is by 'user_login'.
         $ordersby = array('user_login' => $order);
     } elseif (is_array($qv['orderby'])) {
         $ordersby = $qv['orderby'];
     } else {
         // 'orderby' values may be a comma- or space-separated list.
         $ordersby = preg_split('/[,\\s]+/', $qv['orderby']);
     }
     $orderby_array = array();
     foreach ($ordersby as $_key => $_value) {
         if (!$_value) {
             continue;
         }
         if (is_int($_key)) {
             // Integer key means this is a flat array of 'orderby' fields.
             $_orderby = $_value;
             $_order = $order;
         } else {
             // Non-integer key means this the key is the field and the value is ASC/DESC.
             $_orderby = $_key;
             $_order = $_value;
         }
         $parsed = $this->parse_orderby($_orderby);
         if (!$parsed) {
             continue;
开发者ID:kadrim1,项目名称:metsayhistu,代码行数:67,代码来源:class-wp-user-query.php

示例2: test_has_or_relation_should_return_true_for_nested_or

 /**
  * @group 32592
  */
 public function test_has_or_relation_should_return_true_for_nested_or()
 {
     $q = new WP_Meta_Query(array('relation' => 'AND', array('key' => 'foo', 'value' => 'bar'), array('relation' => 'OR', array('key' => 'foo1', 'value' => 'bar'), array('key' => 'foo2', 'value' => 'bar'))));
     $this->assertTrue($q->has_or_relation());
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:8,代码来源:query.php


注:本文中的WP_Meta_Query::has_or_relation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。