• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WP_Meta_Query类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: get_sql

 function get_sql()
 {
     global $wpdb;
     if (empty($this->queries)) {
         return array('join' => '', 'where' => '');
     }
     $context_table = MainWP_WP_Stream_DB::$table_context;
     $main_table = MainWP_WP_Stream_DB::$table;
     $meta_id_column = 'meta_id';
     $join = array();
     $where = array();
     $queries = $this->queries;
     $meta_query = new WP_Meta_Query();
     foreach ($queries as $i => $query) {
         foreach ($query as $key => $args) {
             $type = $meta_query->get_cast_for_type(isset($args['type']) ? $args['type'] : '');
             $value = isset($args['value']) ? $args['value'] : null;
             // Allow 'context' => array('val1', 'val2') as well
             if (is_null($value)) {
                 $args = array('value' => $args);
                 $value = $args['value'];
             }
             if (isset($args['compare'])) {
                 $compare = strtoupper($args['compare']);
             } else {
                 $compare = is_array($value) ? 'IN' : '=';
             }
             $operators = array('=', '!=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'REGEXP', 'NOT REGEXP', 'RLIKE');
             if (!in_array($compare, $operators)) {
                 $compare = '=';
             }
             if ('IN' === substr($compare, -2)) {
                 if (!is_array($value)) {
                     $value = preg_split('/[,\\s]+/', $value);
                 }
                 $compare_string = '(' . substr(str_repeat(',%s', count($value)), 1) . ')';
             } elseif ('LIKE' === substr($compare, -4)) {
                 $value = '%' . like_escape($value) . '%';
                 $compare_string = '%s';
             } else {
                 $compare_string = '%s';
             }
             if (!empty($where[$i])) {
                 $where[$i] .= ' AND ';
             } else {
                 $where[$i] = '';
             }
             $where[$i] = ' (' . $where[$i] . $wpdb->prepare("CAST({$context_table}.{$key} AS {$type}) {$compare} {$compare_string})", $value);
         }
     }
     $where = array_filter($where);
     if (empty($where)) {
         $where = '';
     } else {
         $where = ' AND (' . implode("\n{$this->relation} ", $where) . ' )';
     }
     $join = implode("\n", $join);
     return apply_filters_ref_array('get_context_sql', array(compact('join', 'where'), $this->queries));
 }
开发者ID:HasClass0,项目名称:mainwp-child-reports,代码行数:59,代码来源:context-query.php


示例2: test_empty_value_sql

	/**
	 * @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:staylor,项目名称:develop.svn.wordpress.org,代码行数:25,代码来源:query.php


示例3: 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


示例4: 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


示例5: get_meta_query_sql

 /**
  * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get()
  *
  * We use WP_Meta_Query to do the heavy lifting of parsing the
  * meta_query array and creating the necessary SQL clauses. However,
  * since BP_Activity_Activity::get() builds its SQL differently than
  * WP_Query, we have to alter the return value (stripping the leading
  * AND keyword from the 'where' clause).
  *
  * @since 1.8.0
  *
  * @param array $meta_query An array of meta_query filters. See the
  *                          documentation for {@link WP_Meta_Query} for details.
  * @return array $sql_array 'join' and 'where' clauses.
  */
 protected static function get_meta_query_sql($meta_query = array())
 {
     global $wpdb;
     $sql_array = array('join' => '', 'where' => '');
     if (!empty($meta_query)) {
         $groups_meta_query = new WP_Meta_Query($meta_query);
         // WP_Meta_Query expects the table name at
         // $wpdb->group.
         $wpdb->groupmeta = buddypress()->groups->table_name_groupmeta;
         $meta_sql = $groups_meta_query->get_sql('group', 'g', 'id');
         // BP_Groups_Group::get uses the comma syntax for table
         // joins, which means that we have to do some regex to
         // convert the INNER JOIN and move the ON clause to a
         // WHERE condition
         //
         // @todo It may be better in the long run to refactor
         // the more general query syntax to accord better with
         // BP/WP convention.
         preg_match_all('/JOIN (.+?) ON/', $meta_sql['join'], $matches_a);
         preg_match_all('/ON \\((.+?)\\)/', $meta_sql['join'], $matches_b);
         if (!empty($matches_a[1]) && !empty($matches_b[1])) {
             $sql_array['join'] = implode(',', $matches_a[1]) . ', ';
             $sql_array['where'] = $meta_sql['where'] . ' AND ' . implode(' AND ', $matches_b[1]);
         }
     }
     return $sql_array;
 }
开发者ID:swissspidy,项目名称:BuddyPress,代码行数:42,代码来源:class-bp-groups-group.php


示例6: 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));
开发者ID:WackoMako,项目名称:stonedape,代码行数:67,代码来源:search.php


示例7: test_get_cast_for_type

	/**
	 * @ticket 23033
	 */
	function test_get_cast_for_type() {
		$query = new WP_Meta_Query();
		$this->assertEquals( 'BINARY', $query->get_cast_for_type( 'BINARY' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'CHAR' ) );
		$this->assertEquals( 'DATE', $query->get_cast_for_type( 'DATE' ) );
		$this->assertEquals( 'DATETIME', $query->get_cast_for_type( 'DATETIME' ) );
		$this->assertEquals( 'SIGNED', $query->get_cast_for_type( 'SIGNED' ) );
		$this->assertEquals( 'UNSIGNED', $query->get_cast_for_type( 'UNSIGNED' ) );
		$this->assertEquals( 'TIME', $query->get_cast_for_type( 'TIME' ) );
		$this->assertEquals( 'SIGNED', $query->get_cast_for_type( 'NUMERIC' ) );
		$this->assertEquals( 'NUMERIC(10)', $query->get_cast_for_type( 'NUMERIC(10)' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10)' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10 )' ) );
		$this->assertEquals( 'NUMERIC(10, 5)', $query->get_cast_for_type( 'NUMERIC(10, 5)' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'NUMERIC(10,  5)' ) );
		$this->assertEquals( 'NUMERIC(10,5)', $query->get_cast_for_type( 'NUMERIC(10,5)' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10, 5 )' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'NUMERIC(10, 5 )' ) );
		$this->assertEquals( 'DECIMAL', $query->get_cast_for_type( 'DECIMAL' ) );
		$this->assertEquals( 'DECIMAL(10)', $query->get_cast_for_type( 'DECIMAL(10)' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'DECIMAL( 10 )' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'DECIMAL( 10)' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'DECIMAL(10 )' ) );
		$this->assertEquals( 'DECIMAL(10, 5)', $query->get_cast_for_type( 'DECIMAL(10, 5)' ) );
		$this->assertEquals( 'DECIMAL(10,5)', $query->get_cast_for_type( 'DECIMAL(10,5)' ) );
		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'DECIMAL(10,  5)' ) );

		$this->assertEquals( 'CHAR', $query->get_cast_for_type( 'ANYTHING ELSE' ) );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:32,代码来源:query.php


示例8: meta_where

 /**
  * Inject the meta_query SQL in SearchWP's WHERE
  *
  * @since 2.6
  *
  * @param $sql
  * @param $engine
  *
  * @return string
  */
 function meta_where($sql, $engine)
 {
     if ($engine != $this->engine || empty($this->meta_query) || !is_array($this->meta_query)) {
         return $sql;
     }
     global $wpdb;
     $meta_query = new WP_Meta_Query($this->meta_query);
     $mq_sql = $meta_query->get_sql('post', $wpdb->posts, 'ID', null);
     return $sql . $mq_sql['where'];
 }
开发者ID:acutedeveloper,项目名称:havering-intranet-development,代码行数:20,代码来源:class.swp-query.php


示例9: get_meta_query_sql

 /**
  * Get the SQL for the 'meta_query' param in BP_Notifications_Notification::get().
  *
  * We use WP_Meta_Query to do the heavy lifting of parsing the
  * meta_query array and creating the necessary SQL clauses. However,
  * since BP_Notifications_Notification::get() builds its SQL differently than
  * WP_Query, we have to alter the return value (stripping the leading
  * AND keyword from the 'where' clause).
  *
  * @since 2.3.0
  *
  * @param  array $meta_query An array of meta_query filters. See the
  *                           documentation for WP_Meta_Query for details.
  * @return array $sql_array 'join' and 'where' clauses.
  */
 public static function get_meta_query_sql($meta_query = array())
 {
     // Default array keys & empty values.
     $sql_array = array('join' => '', 'where' => '');
     // Bail if no meta query.
     if (empty($meta_query)) {
         return $sql_array;
     }
     // WP_Meta_Query expects the table name at $wpdb->notificationmeta.
     $GLOBALS['wpdb']->notificationmeta = buddypress()->notifications->table_name_meta;
     $n_meta_query = new WP_Meta_Query($meta_query);
     $meta_sql = $n_meta_query->get_sql('notification', 'n', 'id');
     // Strip the leading AND - it's handled in get().
     $sql_array['where'] = preg_replace('/^\\sAND/', '', $meta_sql['where']);
     $sql_array['join'] = $meta_sql['join'];
     return $sql_array;
 }
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:32,代码来源:class-bp-notifications-notification.php


示例10: __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


示例11: 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


示例12: get_filtered_term_product_counts

 /**
  * Count products within certain terms, taking the main WP query into consideration.
  *
  * @param  array  $term_ids
  * @param  string $taxonomy
  * @param  string $query_type
  * @return array
  */
 protected function get_filtered_term_product_counts($term_ids, $taxonomy, $query_type)
 {
     global $wpdb;
     $tax_query = WC_Query::get_main_tax_query();
     $meta_query = WC_Query::get_main_meta_query();
     if ('or' === $query_type) {
         foreach ($tax_query as $key => $query) {
             if (is_array($query) && $taxonomy === $query['taxonomy']) {
                 unset($tax_query[$key]);
             }
         }
     }
     $meta_query = new WP_Meta_Query($meta_query);
     $tax_query = new WP_Tax_Query($tax_query);
     $meta_query_sql = $meta_query->get_sql('post', $wpdb->posts, 'ID');
     $tax_query_sql = $tax_query->get_sql($wpdb->posts, 'ID');
     // Generate query
     $query = array();
     $query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count, terms.term_id as term_count_id";
     $query['from'] = "FROM {$wpdb->posts}";
     $query['join'] = "\n\t\t\tINNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id\n\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id )\n\t\t\tINNER JOIN {$wpdb->terms} AS terms USING( term_id )\n\t\t\t" . $tax_query_sql['join'] . $meta_query_sql['join'];
     $query['where'] = "\n\t\t\tWHERE {$wpdb->posts}.post_type IN ( 'product' )\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\t" . $tax_query_sql['where'] . $meta_query_sql['where'] . "\n\t\t\tAND terms.term_id IN (" . implode(',', array_map('absint', $term_ids)) . ")\n\t\t";
     if ($search = WC_Query::get_main_search_query_sql()) {
         $query['where'] .= ' AND ' . $search;
     }
     $query['group_by'] = "GROUP BY terms.term_id";
     $query = apply_filters('woocommerce_get_filtered_term_product_counts_query', $query);
     $query = implode(' ', $query);
     $results = $wpdb->get_results($query);
     return wp_list_pluck($results, 'term_count', 'term_count_id');
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:39,代码来源:class-wc-widget-layered-nav.php


示例13: 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


示例14: test_empty_compare

 function test_empty_compare()
 {
     global $wpdb;
     $query = new WP_Meta_Query(array('relation' => 'OR', array('key' => 'exclude', 'compare' => ''), array('key' => 'exclude', 'compare' => '!=', 'value' => '1')));
     $sql = $query->get_sql('post', $wpdb->posts, 'ID', $this);
     $this->assertContains("{$wpdb->postmeta}.meta_key = 'exclude'\nOR", $sql['where']);
     $this->assertNotContains("{$wpdb->postmeta}.post_id IS NULL", $sql['where']);
 }
开发者ID:boonebgorges,项目名称:wp,代码行数:8,代码来源:query.php


示例15: get_filtered_term_product_counts

 /**
  * Count products within certain terms, taking the main WP query into consideration.
  * @param  array $term_ids
  * @param  string $taxonomy
  * @param  string $query_type
  * @return array
  */
 protected function get_filtered_term_product_counts($term_ids, $taxonomy, $query_type)
 {
     global $wpdb;
     $tax_query = WC_Query::get_main_tax_query();
     $meta_query = WC_Query::get_main_meta_query();
     if ('or' === $query_type) {
         foreach ($tax_query as $key => $query) {
             if ($taxonomy === $query['taxonomy']) {
                 unset($tax_query[$key]);
             }
         }
     }
     $meta_query = new WP_Meta_Query($meta_query);
     $tax_query = new WP_Tax_Query($tax_query);
     $meta_query_sql = $meta_query->get_sql('post', $wpdb->posts, 'ID');
     $tax_query_sql = $tax_query->get_sql($wpdb->posts, 'ID');
     $sql = "\n\t\t\tSELECT COUNT( {$wpdb->posts}.ID ) as term_count, term_count_relationships.term_taxonomy_id as term_count_id FROM {$wpdb->posts}\n\t\t\tINNER JOIN {$wpdb->term_relationships} AS term_count_relationships ON ({$wpdb->posts}.ID = term_count_relationships.object_id)\n\t\t\t" . $tax_query_sql['join'] . $meta_query_sql['join'] . "\n\t\t\tWHERE {$wpdb->posts}.post_type = 'product' AND {$wpdb->posts}.post_status = 'publish'\n\t\t\t" . $tax_query_sql['where'] . $meta_query_sql['where'] . "\n\t\t\tAND term_count_relationships.term_taxonomy_id IN (" . implode(',', array_map('absint', $term_ids)) . ")\n\t\t\tGROUP BY term_count_relationships.term_taxonomy_id;\n\t\t";
     $results = $wpdb->get_results($sql);
     return wp_list_pluck($results, 'term_count', 'term_count_id');
 }
开发者ID:coderkevin,项目名称:woocommerce,代码行数:27,代码来源:class-wc-widget-layered-nav.php


示例16: get_meta_query_sql

 /**
  * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get()
  *
  * We use WP_Meta_Query to do the heavy lifting of parsing the
  * meta_query array and creating the necessary SQL clauses. However,
  * since BP_Activity_Activity::get() builds its SQL differently than
  * WP_Query, we have to alter the return value (stripping the leading
  * AND keyword from the 'where' clause).
  *
  * @since BuddyPress (1.8)
  *
  * @param array $meta_query An array of meta_query filters. See the
  *   documentation for WP_Meta_Query for details.
  * @return array $sql_array 'join' and 'where' clauses
  */
 public static function get_meta_query_sql($meta_query = array())
 {
     global $wpdb;
     $sql_array = array('join' => '', 'where' => '');
     if (!empty($meta_query)) {
         $activity_meta_query = new WP_Meta_Query($meta_query);
         // WP_Meta_Query expects the table name at
         // $wpdb->activitymeta
         $wpdb->activitymeta = buddypress()->activity->table_name_meta;
         $meta_sql = $activity_meta_query->get_sql('activity', 'a', 'id');
         // Strip the leading AND - BP handles it in get()
         $sql_array['where'] = preg_replace('/^\\sAND/', '', $meta_sql['where']);
         $sql_array['join'] = $meta_sql['join'];
     }
     return $sql_array;
 }
开发者ID:novichkovv,项目名称:candoweightloss,代码行数:31,代码来源:bp-activity-classes.php


示例17: get_filtered_product_count

 /**
  * Count products after other filters have occured by adjusting the main query.
  * @param  int $rating
  * @return int
  */
 protected function get_filtered_product_count($rating)
 {
     global $wpdb;
     $tax_query = WC_Query::get_main_tax_query();
     $meta_query = WC_Query::get_main_meta_query();
     // Unset current rating filter.
     foreach ($tax_query as $key => $query) {
         if (!empty($query['rating_filter'])) {
             unset($tax_query[$key]);
             break;
         }
     }
     // Set new rating filter.
     $product_visibility_terms = wc_get_product_visibility_term_ids();
     $tax_query[] = array('taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', 'terms' => $product_visibility_terms['rated-' . $rating], 'operator' => 'IN', 'rating_filter' => true);
     $meta_query = new WP_Meta_Query($meta_query);
     $tax_query = new WP_Tax_Query($tax_query);
     $meta_query_sql = $meta_query->get_sql('post', $wpdb->posts, 'ID');
     $tax_query_sql = $tax_query->get_sql($wpdb->posts, 'ID');
     $sql = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) FROM {$wpdb->posts} ";
     $sql .= $tax_query_sql['join'] . $meta_query_sql['join'];
     $sql .= " WHERE {$wpdb->posts}.post_type = 'product' AND {$wpdb->posts}.post_status = 'publish' ";
     $sql .= $tax_query_sql['where'] . $meta_query_sql['where'];
     return absint($wpdb->get_var($sql));
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:30,代码来源:class-wc-widget-rating-filter.php


示例18: hm_add_term_meta_query_support

function hm_add_term_meta_query_support($pieces, $taxonomies, $args)
{
    if (empty($args['meta_query'])) {
        return $pieces;
    }
    $meta_query = new WP_Meta_Query($args['meta_query']);
    $sql = $meta_query->get_sql('term', 't', 'term_id');
    if (!$sql) {
        return $pieces;
    }
    $pieces['join'] .= $sql['join'];
    $pieces['where'] .= $sql['where'];
    return $pieces;
}
开发者ID:peterwilsoncc,项目名称:termmeta,代码行数:14,代码来源:termmeta.php


示例19: prepare_query


//.........这里部分代码省略.........
         $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


示例20: get_filtered_price

 public static function get_filtered_price($mode = 'yes')
 {
     global $wpdb, $wp_the_query;
     $args = $wp_the_query->query_vars;
     $tax_query = $mode == 'yes' && isset($args['tax_query']) ? $args['tax_query'] : array();
     $meta_query = $mode == 'yes' && isset($args['meta_query']) ? $args['meta_query'] : array();
     /*
     			if ( ! empty( $args['taxonomy'] ) && ! empty( $args['term'] ) ) {
     				$tax_query[] = array(
     					'taxonomy' => $args['taxonomy'],
     					'terms'    => array( $args['term'] ),
     					'field'    => 'slug',
     				);
     			}
     
     			foreach ( $meta_query as $key => $query ) {
     				if ( ! empty( $query['price_filter'] ) || ! empty( $query['rating_filter'] ) ) {
     					unset( $meta_query[ $key ] );
     				}
     			}
     */
     $meta_query = new WP_Meta_Query($meta_query);
     $tax_query = new WP_Tax_Query($tax_query);
     $meta_query_sql = $meta_query->get_sql('post', $wpdb->posts, 'ID');
     $tax_query_sql = $tax_query->get_sql($wpdb->posts, 'ID');
     $sql = "SELECT min( CAST( price_meta.meta_value AS UNSIGNED ) ) as min_price, max( CAST( price_meta.meta_value AS UNSIGNED ) ) as max_price FROM {$wpdb->posts} ";
     $sql .= " LEFT JOIN {$wpdb->postmeta} as price_meta ON {$wpdb->posts}.ID = price_meta.post_id " . $tax_query_sql['join'] . $meta_query_sql['join'];
     $sql .= " \tWHERE {$wpdb->posts}.post_type = 'product'\r\n\t\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\r\n\t\t\t\t\t\tAND price_meta.meta_key IN ('" . implode("','", array_map('esc_sql', apply_filters('prdctfltr_price_meta_keys', array('_price', '_sale_price', '_min_variation_price', '_min_variation_sale_price', '_max_variation_price', '_max_variation_sale_price')))) . "')\r\n\t\t\t\t\t\tAND price_meta.meta_value > '' ";
     $sql .= $tax_query_sql['where'] . $meta_query_sql['where'];
     $prices = $wpdb->get_row($sql);
     if ($prices->min_price <= 0 && $prices->min_price <= 0) {
         return self::get_filtered_price('no');
     } else {
         return $prices;
     }
 }
开发者ID:arobbins,项目名称:spellestate,代码行数:36,代码来源:prdctfltr.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WP_Mock类代码示例发布时间:2022-05-23
下一篇:
PHP WP_MatchesMapRegex类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap