^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_meta_sql()用法示例

get_meta_sql( array $meta_query,  string $type,  string $primary_table,  string $primary_id_column,  object $context = null )

Given a meta query, generates SQL clauses to be appended to a main query.


描述


参数

$meta_query

(array)
(Required)
A meta query.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

$type

(string)
(Required)
Type of meta.

$primary_table

(string)
(Required)
Primary database table name.

$primary_id_column

(string)
(Required)
Primary ID column name.

$context

(object)
(Optional)
The main query object

Default value: null


返回值

(array) Associative array of JOIN and WHERE SQL.


源代码

File: wp-includes/meta.php

function get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context = null ) {
	$meta_query_obj = new WP_Meta_Query( $meta_query );
	return $meta_query_obj->get_sql( $type, $primary_table, $primary_id_column, $context );
}

更新日志

Version 描述
3.2.0 Introduced.

相关函数

Uses

  • wp-includes/class-wp-meta-query.php:
    WP_Meta_Query::__construct()

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example

    
    <?php  
    $meta_query = array(
    	array(
    		'key' => 'color',
    		'value' => 'blue',
    		'compare' => 'NOT LIKE'
    	)
    );
    global $wpdb;
    $meta_sql = get_meta_sql( $meta_query, 'post', $wpdb->posts, 'ID' );
    

    Output depending on the meta query:

    
    Array
    (
        [join] =>  INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
        [where] =>  AND ( (wp_postmeta.meta_key = 'color' AND CAST(wp_postmeta.meta_value AS CHAR) NOT LIKE '%blue%') )
    )
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈