BP_Notifications_Notification::get_meta_query_sql( array $meta_query = array() )
Get the SQL for the ‘meta_query’ param in BP_Notifications_Notification::get().
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_Notifications_Notification::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
- $meta_query
-
(Optional) An array of meta_query filters. See the documentation for WP_Meta_Query for details.
Default value: array()
Return
(array) $sql_array 'join' and 'where' clauses.
Source
File: bp-notifications/classes/class-bp-notifications-notification.php
public static function get_meta_query_sql( $meta_query = array() ) { // Default array keys & empty values. $sql_array = array( 'join' => '', 'where' => '', ); // Bail if no meta query. if ( empty( $meta_query ) ) { return $sql_array; } // WP_Meta_Query expects the table name at $wpdb->notificationmeta. $GLOBALS['wpdb']->notificationmeta = buddypress()->notifications->table_name_meta; $n_meta_query = new WP_Meta_Query( $meta_query ); $meta_sql = $n_meta_query->get_sql( 'notification', 'n', 'id' ); // Strip the leading AND - it's handled in get(). $sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] ); $sql_array['join'] = $meta_sql['join']; return $sql_array; }
Changelog
Version | Description |
---|---|
BuddyPress 2.3.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.