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


PHP WP_Meta_Query::get_clauses方法代码示例

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


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

示例1: parse_orderby

 /**
  * Parse and sanitize 'orderby' keys passed to the user query.
  *
  * @since 4.2.0
  * @access protected
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param string $orderby Alias for the field to order by.
  * @return string Value to used in the ORDER clause, if `$orderby` is valid.
  */
 protected function parse_orderby($orderby)
 {
     global $wpdb;
     $meta_query_clauses = $this->meta_query->get_clauses();
     $_orderby = '';
     if (in_array($orderby, array('login', 'nicename', 'email', 'url', 'registered'))) {
         $_orderby = 'user_' . $orderby;
     } elseif (in_array($orderby, array('user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered'))) {
         $_orderby = $orderby;
     } elseif ('name' == $orderby || 'display_name' == $orderby) {
         $_orderby = 'display_name';
     } elseif ('post_count' == $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' == $orderby || 'id' == $orderby) {
         $_orderby = 'ID';
     } elseif ('meta_value' == $orderby || $this->get('meta_key') == $orderby) {
         $_orderby = "{$wpdb->usermeta}.meta_value";
     } elseif ('meta_value_num' == $orderby) {
         $_orderby = "{$wpdb->usermeta}.meta_value+0";
     } elseif ('include' === $orderby && !empty($this->query_vars['include'])) {
         $include = wp_parse_id_list($this->query_vars['include']);
         $include_sql = implode(',', $include);
         $_orderby = "FIELD( {$wpdb->users}.ID, {$include_sql} )";
     } elseif (isset($meta_query_clauses[$orderby])) {
         $meta_clause = $meta_query_clauses[$orderby];
         $_orderby = sprintf("CAST(%s.meta_value AS %s)", esc_sql($meta_clause['alias']), esc_sql($meta_clause['cast']));
     }
     return $_orderby;
 }
开发者ID:kadrim1,项目名称:metsayhistu,代码行数:43,代码来源:class-wp-user-query.php

示例2: get_terms


//.........这里部分代码省略.........
    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)) {
                        // $orderby corresponds to a meta_query clause.
                        $meta_clause = $meta_clauses[$args['orderby']];
开发者ID:Andremyid,项目名称:WordPress,代码行数:67,代码来源:taxonomy.php


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