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


PHP WP_Meta_Query::parse_query_vars方法代码示例

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


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

示例1: terms_clauses

 /**
  * terms_clauses
  * Clause updates for term queries.
  *
  * @param array $pieces The pieces of the sql query
  * @param array $taxonomies The taxonomies for the query
  * @param array $arguments The arguments for the query
  *
  * @return array $pieces
  *
  * @access public
  * @static
  * @since 1.0
  */
 public static function terms_clauses($pieces = array(), $taxonomies = array(), $arguments = array())
 {
     if (!empty($arguments['meta_query'])) {
         $query = new WP_Meta_Query($arguments['meta_query']);
         $query->parse_query_vars($arguments);
         if (!empty($query->queries)) {
             $clauses = $query->get_sql('term', 'tt', 'term_id', $taxonomies);
             $pieces['join'] .= $clauses['join'];
             $pieces['where'] .= $clauses['where'];
         }
     }
     return $pieces;
 }
开发者ID:a42,项目名称:piklist,代码行数:27,代码来源:class-piklist-taxonomy.php

示例2: wpToLabel

 /**
  * Convert WP_Query query_var value into a human readable label
  *
  * @param array $query_vars WP_Query query vars.
  * @return string the label based on the given vars.
  */
 public function wpToLabel($query_vars)
 {
     $meta_query = new WP_Meta_Query();
     $meta_query->parse_query_vars($query_vars);
     $label = '';
     if (count($meta_query->queries) > 0) {
         $expressionSet = new Lift_Expression_Set(strtolower($meta_query->relation));
         foreach ($meta_query->queries as $subquery) {
             if ($subquery['key'] == $this->meta_key) {
                 $label = (string) $subquery->value;
             }
         }
     }
     return $label;
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:21,代码来源:field.php

示例3: array

 /**
  * @ticket 22096
  */
 function test_empty_value_sql()
 {
     global $wpdb;
     $query = new WP_Meta_Query();
     $the_complex_query['meta_query'] = array(array('key' => 'my_first_key', 'value' => 'my_amazing_value'), array('key' => 'my_second_key', 'compare' => 'NOT EXISTS'), array('key' => 'my_third_key', 'value' => array(), 'compare' => 'IN'));
     $query->parse_query_vars($the_complex_query);
     $sql = $query->get_sql('post', $wpdb->posts, 'ID', $this);
     // We should have 2 joins - one for my_first_key and one for my_second_key
     $this->assertEquals(2, substr_count($sql['join'], 'INNER JOIN'));
     // The WHERE should check my_third_key against an unaliased table
     $this->assertEquals(1, substr_count($sql['where'], "{$wpdb->postmeta}.meta_key = 'my_third_key'"));
 }
开发者ID:boonebgorges,项目名称:wp,代码行数:15,代码来源:query.php

示例4: prepare_query


//.........这里部分代码省略.........
     $this->query_from = "FROM {$wpdb->users}";
     $this->query_where = "WHERE 1=1";
     // Parse and sanitize 'include', for use by 'orderby' as well as 'include' below.
     if (!empty($qv['include'])) {
         $include = wp_parse_id_list($qv['include']);
     } else {
         $include = false;
     }
     $blog_id = 0;
     if (isset($qv['blog_id'])) {
         $blog_id = absint($qv['blog_id']);
     }
     if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) {
         $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
         $qv['meta_value'] = 0;
         $qv['meta_compare'] = '!=';
         $qv['blog_id'] = $blog_id = 0;
         // Prevent extra meta query
     }
     if ($qv['has_published_posts'] && $blog_id) {
         if (true === $qv['has_published_posts']) {
             $post_types = get_post_types(array('public' => true));
         } else {
             $post_types = (array) $qv['has_published_posts'];
         }
         foreach ($post_types as &$post_type) {
             $post_type = $wpdb->prepare('%s', $post_type);
         }
         $posts_table = $wpdb->get_blog_prefix($blog_id) . 'posts';
         $this->query_where .= " AND {$wpdb->users}.ID IN ( SELECT DISTINCT {$posts_table}.post_author FROM {$posts_table} WHERE {$posts_table}.post_status = 'publish' AND {$posts_table}.post_type IN ( " . join(", ", $post_types) . " ) )";
     }
     // Meta query.
     $this->meta_query = new WP_Meta_Query();
     $this->meta_query->parse_query_vars($qv);
     $roles = array();
     if (isset($qv['role'])) {
         if (is_array($qv['role'])) {
             $roles = $qv['role'];
         } elseif (is_string($qv['role']) && !empty($qv['role'])) {
             $roles = array_map('trim', explode(',', $qv['role']));
         }
     }
     $role__in = array();
     if (isset($qv['role__in'])) {
         $role__in = (array) $qv['role__in'];
     }
     $role__not_in = array();
     if (isset($qv['role__not_in'])) {
         $role__not_in = (array) $qv['role__not_in'];
     }
     if ($blog_id && (!empty($roles) || !empty($role__in) || !empty($role__not_in) || is_multisite())) {
         $role_queries = array();
         $roles_clauses = array('relation' => 'AND');
         if (!empty($roles)) {
             foreach ($roles as $role) {
                 $roles_clauses[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => '"' . $role . '"', 'compare' => 'LIKE');
             }
             $role_queries[] = $roles_clauses;
         }
         $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;
         }
开发者ID:kadrim1,项目名称:metsayhistu,代码行数:67,代码来源:class-wp-user-query.php

示例5: array


//.........这里部分代码省略.........
         $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
     }
     $this->query_from = "FROM {$wpdb->users}";
     $this->query_where = "WHERE 1=1";
     // sorting
     if (in_array($qv['orderby'], array('nicename', 'email', 'url', 'registered'))) {
         $orderby = 'user_' . $qv['orderby'];
     } elseif (in_array($qv['orderby'], array('user_nicename', 'user_email', 'user_url', 'user_registered'))) {
         $orderby = $qv['orderby'];
     } elseif ('name' == $qv['orderby'] || 'display_name' == $qv['orderby']) {
         $orderby = 'display_name';
     } elseif ('post_count' == $qv['orderby']) {
         // todo: avoid the JOIN
         $where = get_posts_by_author_sql('post');
         $this->query_from .= " LEFT OUTER JOIN (\n\t\t\t\tSELECT post_author, COUNT(*) as post_count\n\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t{$where}\n\t\t\t\tGROUP BY post_author\n\t\t\t) p ON ({$wpdb->users}.ID = p.post_author)\n\t\t\t";
         $orderby = 'post_count';
     } elseif ('ID' == $qv['orderby'] || 'id' == $qv['orderby']) {
         $orderby = 'ID';
     } else {
         $orderby = 'user_login';
     }
     $qv['order'] = strtoupper($qv['order']);
     if ('ASC' == $qv['order']) {
         $order = 'ASC';
     } else {
         $order = 'DESC';
     }
     $this->query_orderby = "ORDER BY {$orderby} {$order}";
     // limit
     if ($qv['number']) {
         if ($qv['offset']) {
             $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
         } else {
             $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
         }
     }
     $search = trim($qv['search']);
     if ($search) {
         $leading_wild = ltrim($search, '*') != $search;
         $trailing_wild = rtrim($search, '*') != $search;
         if ($leading_wild && $trailing_wild) {
             $wild = 'both';
         } elseif ($leading_wild) {
             $wild = 'leading';
         } elseif ($trailing_wild) {
             $wild = 'trailing';
         } else {
             $wild = false;
         }
         if ($wild) {
             $search = trim($search, '*');
         }
         if (false !== strpos($search, '@')) {
             $search_columns = array('user_email');
         } elseif (is_numeric($search)) {
             $search_columns = array('user_login', 'ID');
         } elseif (preg_match('|^https?://|', $search)) {
             $search_columns = array('user_url');
         } else {
             $search_columns = array('user_login', 'user_nicename');
         }
         $this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
     }
     $blog_id = absint($qv['blog_id']);
     if ('authors' == $qv['who'] && $blog_id) {
         $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
         $qv['meta_value'] = 0;
         $qv['meta_compare'] = '!=';
         $qv['blog_id'] = $blog_id = 0;
         // Prevent extra meta query
     }
     $role = trim($qv['role']);
     if ($blog_id && ($role || is_multisite())) {
         $cap_meta_query = array();
         $cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id) . 'capabilities';
         if ($role) {
             $cap_meta_query['value'] = '"' . $role . '"';
             $cap_meta_query['compare'] = 'like';
         }
         $qv['meta_query'][] = $cap_meta_query;
     }
     $meta_query = new WP_Meta_Query();
     $meta_query->parse_query_vars($qv);
     if (!empty($meta_query->queries)) {
         $clauses = $meta_query->get_sql('user', $wpdb->users, 'ID', $this);
         $this->query_from .= $clauses['join'];
         $this->query_where .= $clauses['where'];
         if ('OR' == $meta_query->relation) {
             $this->query_fields = 'DISTINCT ' . $this->query_fields;
         }
     }
     if (!empty($qv['include'])) {
         $ids = implode(',', wp_parse_id_list($qv['include']));
         $this->query_where .= " AND {$wpdb->users}.ID IN ({$ids})";
     } elseif (!empty($qv['exclude'])) {
         $ids = implode(',', wp_parse_id_list($qv['exclude']));
         $this->query_where .= " AND {$wpdb->users}.ID NOT IN ({$ids})";
     }
     do_action_ref_array('pre_user_query', array(&$this));
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:101,代码来源:user.php

示例6: array


//.........这里部分代码省略.........
         $trailing_wild = rtrim($search, '*') != $search;
         if ($leading_wild && $trailing_wild) {
             $wild = 'both';
         } elseif ($leading_wild) {
             $wild = 'leading';
         } elseif ($trailing_wild) {
             $wild = 'trailing';
         } else {
             $wild = false;
         }
         if ($wild) {
             $search = trim($search, '*');
         }
         $search_columns = array();
         if ($qv['search_columns']) {
             $search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename'));
         }
         if (!$search_columns) {
             if (false !== strpos($search, '@')) {
                 $search_columns = array('user_email');
             } elseif (is_numeric($search)) {
                 $search_columns = array('user_login', 'ID');
             } elseif (preg_match('|^https?://|', $search) && !(is_multisite() && wp_is_large_network('users'))) {
                 $search_columns = array('user_url');
             } else {
                 $search_columns = array('user_login', 'user_nicename');
             }
         }
         /**
          * Filter the columns to search in a WP_User_Query search.
          *
          * The default columns depend on the search term, and include 'user_email',
          * 'user_login', 'ID', 'user_url', and 'user_nicename'.
          *
          * @since 3.6.0
          *
          * @param array         $search_columns Array of column names to be searched.
          * @param string        $search         Text being searched.
          * @param WP_User_Query $this           The current WP_User_Query instance.
          */
         $search_columns = apply_filters('user_search_columns', $search_columns, $search, $this);
         $this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
     }
     $blog_id = 0;
     if (isset($qv['blog_id'])) {
         $blog_id = absint($qv['blog_id']);
     }
     if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) {
         $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
         $qv['meta_value'] = 0;
         $qv['meta_compare'] = '!=';
         $qv['blog_id'] = $blog_id = 0;
         // Prevent extra meta query
     }
     $role = '';
     if (isset($qv['role'])) {
         $role = trim($qv['role']);
     }
     if ($blog_id && ($role || is_multisite())) {
         $cap_meta_query = array();
         $cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id) . 'capabilities';
         if ($role) {
             $cap_meta_query['value'] = '"' . $role . '"';
             $cap_meta_query['compare'] = 'like';
         }
         if (empty($qv['meta_query']) || !in_array($cap_meta_query, $qv['meta_query'], true)) {
             $qv['meta_query'][] = $cap_meta_query;
         }
     }
     $meta_query = new WP_Meta_Query();
     $meta_query->parse_query_vars($qv);
     if (!empty($meta_query->queries)) {
         $clauses = $meta_query->get_sql('user', $wpdb->users, 'ID', $this);
         $this->query_from .= $clauses['join'];
         $this->query_where .= $clauses['where'];
         if ('OR' == $meta_query->relation) {
             $this->query_fields = 'DISTINCT ' . $this->query_fields;
         }
     }
     if (!empty($qv['include'])) {
         $ids = implode(',', wp_parse_id_list($qv['include']));
         $this->query_where .= " AND {$wpdb->users}.ID IN ({$ids})";
     } elseif (!empty($qv['exclude'])) {
         $ids = implode(',', wp_parse_id_list($qv['exclude']));
         $this->query_where .= " AND {$wpdb->users}.ID NOT IN ({$ids})";
     }
     /**
      * Fires after the WP_User_Query has been parsed, and before
      * the query is executed.
      *
      * The passed WP_User_Query object contains SQL parts formed
      * from parsing the given query.
      *
      * @since 3.1.0
      *
      * @param WP_User_Query $this The current WP_User_Query instance,
      *                            passed by reference.
      */
     do_action_ref_array('pre_user_query', array(&$this));
 }
开发者ID:valiror,项目名称:sharingdais_demo1,代码行数:101,代码来源:user.php

示例7: __construct

 /**
  * Initialize the class
  * @param string|array $args
  */
 public function __construct($args = '')
 {
     global $wpdb;
     ap_wpdb_tables();
     $this->per_page = 20;
     // Grab the current page number and set to 1 if no page number is set.
     $this->paged = isset($args['paged']) ? (int) $args['paged'] : 1;
     $this->offset = $this->per_page * ($this->paged - 1);
     $this->args = wp_parse_args($args, array('number' => $this->per_page, 'offset' => $this->offset, 'orderby' => 'date', 'order' => 'DESC', 'notification' => false));
     // Process meta query arguments.
     if (isset($this->args['meta_query'])) {
         $meta_query = new WP_Meta_Query();
         $meta_query->parse_query_vars($this->args['meta_query']);
         $this->meta_query_sql = $meta_query->get_sql('ap_activity', $wpdb->ap_activity, 'id', null);
     }
     $this->parse_query();
     $this->total_activity_count = $wpdb->get_var(apply_filters('ap_found_activity_query', 'SELECT FOUND_ROWS()', $this));
 }
开发者ID:Krl4,项目名称:anspress,代码行数:22,代码来源:activity.php

示例8: relevanssi_search


//.........这里部分代码省略.........
    }
    if (is_array($parent_query)) {
        if (!empty($parent_query['parent in'])) {
            $valid_values = array();
            foreach ($parent_query['parent in'] as $post_in_id) {
                if (is_numeric($post_in_id)) {
                    $valid_values[] = $post_in_id;
                }
            }
            $posts = implode(',', $valid_values);
            if (!empty($posts)) {
                $query_restrictions .= " AND relevanssi.doc IN (SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ({$posts}))";
            }
            // Clean: $posts is checked to be integers
        }
        if (!empty($parent_query['parent not in'])) {
            $valid_values = array();
            foreach ($parent_query['parent not in'] as $post_not_in_id) {
                if (is_numeric($post_not_in_id)) {
                    $valid_values[] = $post_not_in_id;
                }
            }
            $posts = implode(',', $valid_values);
            if (!empty($posts)) {
                $query_restrictions .= " AND relevanssi.doc NOT IN (SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ({$posts}))";
            }
            // Clean: $posts is checked to be integers
        }
    }
    if (is_array($meta_query)) {
        $meta_query_restrictions = "";
        $mq_vars = array('meta_query' => $meta_query);
        $mq = new WP_Meta_Query();
        $mq->parse_query_vars($mq_vars);
        $meta_sql = $mq->get_sql('post', 'relevanssi', 'doc');
        $meta_join = "";
        $meta_where = "";
        if ($meta_sql) {
            $meta_join = $meta_sql['join'];
            $meta_where = $meta_sql['where'];
        }
        $query_restrictions .= $meta_where;
    }
    if (!empty($date_query)) {
        if (is_object($date_query) && method_exists($date_query, 'get_sql')) {
            $sql = $date_query->get_sql();
            // AND ( the query itself )
            $query_restrictions .= " AND relevanssi.doc IN ( SELECT DISTINCT(ID) FROM {$wpdb->posts} WHERE 1 {$sql} )";
            // Clean: $sql generated by $date_query->get_sql() query
        }
    }
    if (!$post_type && get_option('relevanssi_respect_exclude') == 'on') {
        if (function_exists('get_post_types')) {
            $pt_1 = get_post_types(array('exclude_from_search' => '0'));
            $pt_2 = get_post_types(array('exclude_from_search' => false));
            $post_type = implode(',', array_merge($pt_1, $pt_2));
        }
    }
    if ($post_type) {
        if ($post_type == -1) {
            $post_type = null;
        }
        // Facetious sets post_type to -1 if not selected
        if (!is_array($post_type)) {
            $post_types = esc_sql(explode(',', $post_type));
        } else {
开发者ID:WackoMako,项目名称:stonedape,代码行数:67,代码来源:search.php

示例9: test_empty_value_sql

	/**
	 * @ticket 22096
	 */
	public function test_empty_value_sql() {
		global $wpdb;

		$query = new WP_Meta_Query();

		$the_complex_query['meta_query'] = array(
			array( 'key' => 'my_first_key', 'value' => 'my_amazing_value' ),
			array( 'key' => 'my_second_key', 'compare' => 'NOT EXISTS' ),
			array( 'key' => 'my_third_key', 'value' => array( ), 'compare' => 'IN' ),
		);

		$query->parse_query_vars( $the_complex_query );

		$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );

		$this->assertEquals( 3, substr_count( $sql['join'], 'JOIN' ) );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:20,代码来源:query.php

示例10: query


//.........这里部分代码省略.........
         if (!empty($author__not_in)) {
             $author__not_in_format = '(' . join(',', array_fill(0, count($author__not_in), '%d')) . ')';
             $where .= $wpdb->prepare(" AND {$wpdb->mainwp_reports}.author NOT IN {$author__not_in_format}", $author__not_in);
         }
     }
     if ($args['author_role__in']) {
         if (!empty($args['author_role__in'])) {
             $author_role__in = '(' . join(',', array_fill(0, count($args['author_role__in']), '%s')) . ')';
             $where .= $wpdb->prepare(" AND {$wpdb->mainwp_reports}.author_role IN {$author_role__in}", $args['author_role__in']);
         }
     }
     if ($args['author_role__not_in']) {
         if (!empty($args['author_role__not_in'])) {
             $author_role__not_in = '(' . join(',', array_fill(0, count($args['author_role__not_in']), '%s')) . ')';
             $where .= $wpdb->prepare(" AND {$wpdb->mainwp_reports}.author_role NOT IN {$author_role__not_in}", $args['author_role__not_in']);
         }
     }
     if ($args['ip__in']) {
         if (!empty($args['ip__in'])) {
             $ip__in = '(' . join(',', array_fill(0, count($args['ip__in']), '%s')) . ')';
             $where .= $wpdb->prepare(" AND {$wpdb->mainwp_reports}.ip IN {$ip__in}", $args['ip__in']);
         }
     }
     if ($args['ip__not_in']) {
         if (!empty($args['ip__not_in'])) {
             $ip__not_in = '(' . join(',', array_fill(0, count($args['ip__not_in']), '%s')) . ')';
             $where .= $wpdb->prepare(" AND {$wpdb->mainwp_reports}.ip NOT IN {$ip__not_in}", $args['ip__not_in']);
         }
     }
     /**
      * PARSE META QUERY PARAMS
      */
     $meta_query = new WP_Meta_Query();
     $meta_query->parse_query_vars($args);
     if (!empty($meta_query->queries)) {
         $mclauses = $meta_query->get_sql('mainwp-child-reports', $wpdb->mainwp_reports, 'ID');
         $join .= str_replace('stream_id', 'record_id', $mclauses['join']);
         $where .= str_replace('stream_id', 'record_id', $mclauses['where']);
     }
     /**
      * PARSE CONTEXT PARAMS
      */
     if (!$args['ignore_context']) {
         $context_query = new MainWP_WP_Stream_Context_Query($args);
         $cclauses = $context_query->get_sql();
         $join .= $cclauses['join'];
         $where .= $cclauses['where'];
     }
     /**
      * PARSE PAGINATION PARAMS
      */
     $page = intval($args['paged']);
     $perpage = intval($args['records_per_page']);
     if ($perpage >= 0) {
         $offset = ($page - 1) * $perpage;
         $limits = "LIMIT {$offset}, {$perpage}";
     } else {
         $limits = '';
     }
     /**
      * PARSE ORDER PARAMS
      */
     $order = esc_sql($args['order']);
     $orderby = esc_sql($args['orderby']);
     $orderable = array('ID', 'site_id', 'blog_id', 'object_id', 'author', 'author_role', 'summary', 'visibility', 'parent', 'type', 'created');
     if (in_array($orderby, $orderable)) {
开发者ID:HasClass0,项目名称:mainwp-child-reports,代码行数:67,代码来源:query.php

示例11: get_terms


//.........这里部分代码省略.........
        $where .= $wpdb->prepare(" AND tt.description LIKE %s", '%' . $wpdb->esc_like($args['description__like']) . '%');
    }
    if ('' !== $parent) {
        $parent = (int) $parent;
        $where .= " AND tt.parent = '{$parent}'";
    }
    $hierarchical = $args['hierarchical'];
    if ('count' == $args['fields']) {
        $hierarchical = false;
    }
    if ($args['hide_empty'] && !$hierarchical) {
        $where .= ' AND tt.count > 0';
    }
    $number = $args['number'];
    $offset = $args['offset'];
    // Don't limit the query results when we have to descend the family tree.
    if ($number && !$hierarchical && !$child_of && '' === $parent) {
        if ($offset) {
            $limits = 'LIMIT ' . $offset . ',' . $number;
        } else {
            $limits = 'LIMIT ' . $number;
        }
    } else {
        $limits = '';
    }
    if (!empty($args['search'])) {
        $like = '%' . $wpdb->esc_like($args['search']) . '%';
        $where .= $wpdb->prepare(' AND ((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like);
    }
    // Meta query support.
    $join = '';
    $distinct = '';
    $mquery = new WP_Meta_Query();
    $mquery->parse_query_vars($args);
    $mq_sql = $mquery->get_sql('term', 't', 'term_id');
    $meta_clauses = $mquery->get_clauses();
    if (!empty($meta_clauses)) {
        $join .= $mq_sql['join'];
        $where .= $mq_sql['where'];
        $distinct .= "DISTINCT";
        // 'orderby' support.
        $allowed_keys = array();
        $primary_meta_key = null;
        $primary_meta_query = reset($meta_clauses);
        if (!empty($primary_meta_query['key'])) {
            $primary_meta_key = $primary_meta_query['key'];
            $allowed_keys[] = $primary_meta_key;
        }
        $allowed_keys[] = 'meta_value';
        $allowed_keys[] = 'meta_value_num';
        $allowed_keys = array_merge($allowed_keys, array_keys($meta_clauses));
        if (!empty($args['orderby']) && in_array($args['orderby'], $allowed_keys)) {
            switch ($args['orderby']) {
                case $primary_meta_key:
                case 'meta_value':
                    if (!empty($primary_meta_query['type'])) {
                        $orderby = "ORDER BY CAST({$primary_meta_query['alias']}.meta_value AS {$primary_meta_query['cast']})";
                    } else {
                        $orderby = "ORDER BY {$primary_meta_query['alias']}.meta_value";
                    }
                    break;
                case 'meta_value_num':
                    $orderby = "ORDER BY {$primary_meta_query['alias']}.meta_value+0";
                    break;
                default:
                    if (array_key_exists($args['orderby'], $meta_clauses)) {
开发者ID:Andremyid,项目名称:WordPress,代码行数:67,代码来源:taxonomy.php

示例12: terms_clauses

 /**
  * Filter `term_clauses` and add support for a `meta_query` argument
  *
  * @since 0.1.0
  *
  * @param array $pieces     Terms query SQL clauses.
  * @param array $taxonomies An array of taxonomies.
  * @param array $args       An array of terms query arguments.
  *
  * @return Array of query pieces, maybe modifed
  */
 public function terms_clauses($pieces = array(), $taxonomies = array(), $args = array())
 {
     // Maybe do a meta query
     if (!empty($args['meta_query'])) {
         // Make doubly sure global database object is prepared
         $this->add_termmeta_to_db_object();
         // Get the meta query parts
         $meta_query = new WP_Meta_Query($args['meta_query']);
         $meta_query->parse_query_vars($args);
         // Combine pieces & meta-query clauses
         if (!empty($meta_query->queries)) {
             /**
              * It's possible in a future version of WordPress that our
              * `term_id` usage might need to be swapped to `term_taxonomy_id`.
              */
             $meta_clauses = $meta_query->get_sql('term', 'tt', 'term_id', $taxonomies);
             $pieces['join'] .= $meta_clauses['join'];
             $pieces['where'] .= $meta_clauses['where'];
         }
     }
     // Return possibly modified pieces array
     return $pieces;
 }
开发者ID:wir,项目名称:wp-term-meta,代码行数:34,代码来源:wp-term-meta.php


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