WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get tax sql

Description

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

Usage

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

Parameters

$tax_query
(array) (required) A compact tax query.
Default: None
$primary_table
(string) (required) Database table you want to append the query to.
Default: None
$primary_id_column
(string) (required) Database primary id column.
Default: None

Return Values

(array).

Examples

<?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:

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) )
)

Change Log

Since: 3.1.0

Source File

get_tax_sql() is located in wp-includes/taxonomy.php540.

Related