當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。