bp_filter_metaid_column_name( string $q )
Filter SQL query strings to swap out the ‘meta_id’ column.
Description
WordPress uses the meta_id column for commentmeta and postmeta, and so hardcodes the column name into its *_metadata() functions. BuddyPress, on the other hand, uses ‘id’ for the primary column. To make WP’s functions usable for BuddyPress, we use this just-in-time filter on ‘query’ to swap ‘meta_id’ with ‘id.
Parameters
- $q
-
(Required) SQL query.
Return
(string)
Source
File: bp-core/bp-core-filters.php
function bp_filter_metaid_column_name( $q ) { /* * Replace quoted content with __QUOTE__ to avoid false positives. * This regular expression will match nested quotes. */ $quoted_regex = "/'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'/s"; preg_match_all( $quoted_regex, $q, $quoted_matches ); $q = preg_replace( $quoted_regex, '__QUOTE__', $q ); $q = str_replace( 'meta_id', 'id', $q ); // Put quoted content back into the string. if ( ! empty( $quoted_matches[0] ) ) { for ( $i = 0; $i < count( $quoted_matches[0] ); $i++ ) { $quote_pos = strpos( $q, '__QUOTE__' ); $q = substr_replace( $q, $quoted_matches[0][ $i ], $quote_pos, 9 ); } } return $q; }
Changelog
Version | Description |
---|---|
BuddyPress 2.0.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.