BP_Activity_Activity::get_meta_query_sql( array $meta_query = array() )

Get the SQL for the ‘meta_query’ param in BP_Activity_Activity::get().


Description Description

We use WP_Meta_Query to do the heavy lifting of parsing the meta_query array and creating the necessary SQL clauses. However, since BP_Activity_Activity::get() builds its SQL differently than WP_Query, we have to alter the return value (stripping the leading AND keyword from the ‘where’ clause).


Parameters Parameters

$meta_query

(Optional) An array of meta_query filters. See the documentation for WP_Meta_Query for details.

Default value: array()


Top ↑

Return Return

(array) $sql_array 'join' and 'where' clauses.


Top ↑

Source Source

File: bp-activity/classes/class-bp-activity-activity.php

	public static function get_meta_query_sql( $meta_query = array() ) {
		global $wpdb;

		$sql_array = array(
			'join'  => '',
			'where' => '',
		);

		if ( ! empty( $meta_query ) ) {
			$activity_meta_query = new WP_Meta_Query( $meta_query );

			// WP_Meta_Query expects the table name at
			// $wpdb->activitymeta.
			$wpdb->activitymeta = buddypress()->activity->table_name_meta;

			$meta_sql = $activity_meta_query->get_sql( 'activity', 'a', 'id' );

			// Strip the leading AND - BP handles it in get().
			$sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] );
			$sql_array['join']  = $meta_sql['join'];
		}

		return $sql_array;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.