WP_Tax_Query::get_sql_clauses() WordPress Method

The WordPress Tax Query is a powerful tool that allows you to create complex SQL queries to retrieve data from the WordPress database. The Tax Query can be used to query any taxonomy, including custom taxonomies. The Tax Query can be used to retrieve data from multiple taxonomies, including child and parent taxonomies. The Tax Query can also be used to retrieve data from multiple terms in a taxonomy.

WP_Tax_Query::get_sql_clauses() #

Generate SQL clauses to be appended to a main query.


Description

Called by the public WP_Tax_Query::get_sql(), this method is abstracted out to maintain parity with the other Query classes.


Top ↑

Return

(string[]) Array containing JOIN and WHERE SQL clauses to append to the main query.

  • 'join'
    (string) SQL fragment to append to the main JOIN clause.
  • 'where'
    (string) SQL fragment to append to the main WHERE clause.


Top ↑

Source

File: wp-includes/class-wp-tax-query.php

	protected function get_sql_clauses() {
		/*
		 * $queries are passed by reference to get_sql_for_query() for recursion.
		 * To keep $this->queries unaltered, pass a copy.
		 */
		$queries = $this->queries;
		$sql     = $this->get_sql_for_query( $queries );

		if ( ! empty( $sql['where'] ) ) {
			$sql['where'] = ' AND ' . $sql['where'];
		}

		return $sql;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.