get_tax_sql()获取分类法的添加筛选条件的SQL查询语句

目录

描述

Given a taxonomy query, generates SQL to be appended to a main query.

get_tax_sql() 描述

用法

<?php get_tax_sql$tax_query$primary_table$primary_id_column ?>

get_tax_sql() 用法

参数

$tax_query

(array) (必填) A compact tax query.

默认值: None

$primary_table

(string) (必填) Database table you want to append the query to.

默认值: None

$primary_id_column

(string) (必填) Database primary id column.

默认值: None

get_tax_sql() 参数

返回值

(array).

get_tax_sql() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?php  
$tax_query = array(
	array(
		'taxonomy' => 'category',
		'field'    => 'slug',
		'terms'    => array( 'cat-a', 'cat-b' ),
	)
);

global $wpdb;
$tax_sql = get_tax_sql( $tax_query, $wpdb->posts, 'ID' );
?>

Output depending on the taxonomy query:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

Array
(
    [join] =>  INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
    [where] =>  AND ( wp_term_relationships.term_taxonomy_id IN (3,4,10,19,25,95) )
)

get_tax_sql() 示例

历史

添加于 版本: 3.1.0

get_tax_sql() 历史

源文件

get_tax_sql() 函数的代码位于 wp-includes/taxonomy.php540.

get_tax_sql() 源文件