BP_XProfile_Query::get_sql( string $primary_table, string $primary_id_column )

Generates SQL clauses to be appended to a main query.

Description

Parameters

$primary_table

(Required) Database table where the object being filtered is stored (eg wp_users).

$primary_id_column

(Required) ID column for the filtered object in $primary_table.

Return

(array) 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.

Source

File: bp-xprofile/classes/class-bp-xprofile-query.php

	public function get_sql( $primary_table, $primary_id_column ) {

		$this->primary_table     = $primary_table;
		$this->primary_id_column = $primary_id_column;

		$sql = $this->get_sql_clauses();

		/*
		 * If any JOINs are LEFT JOINs (as in the case of NOT EXISTS), then all JOINs should
		 * be LEFT. Otherwise posts with no metadata will be excluded from results.
		 */
		if ( false !== strpos( $sql['join'], 'LEFT JOIN' ) ) {
			$sql['join'] = str_replace( 'INNER JOIN', 'LEFT JOIN', $sql['join'] );
		}

		return $sql;
	}

Changelog

Changelog
Version Description
BuddyPress 2.2.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.