That’s strange. I’m assuming you’re passing it an actual group ID (integer)? That’s required. Can you var_dump
what it’s returning?
The result is an empty array. Im setting $single = false.
If i run it like this in functions.php:
add_action('bp_groups_setup_globals', function() {
var_dump(groups_get_groupmeta(2, 'google_group_name', false));
});
It returns the following (Which is correct):
array (size=4)
0 => string ‘vmu’ (length=3)
1 => string ‘alla’ (length=4)
2 => string ‘digital’ (length=7)
3 => string ‘linuxbackup’ (length=11)
It’s probably a timing issue. You’re calling it too early.
Try this hook:
function tim_check() {
var_dump(groups_get_groupmeta(2, 'google_group_name', false));
}
add_action( 'bp_ready', 'tim_check', 11);
Good shout @shanebp.
Also, looking at the groups_get_groupmeta()
function definition, I’m wondering why we need to filter the query string with bp_filter_metaid_column_name
?
Anyway, alternatively, this may work but I haven’t tested:
$retval = get_metadata( 'group', $group_id, $meta_key, $single );
var_dump( $retval );
Edit: Looks as though there is a reason BuddyPress uses bp_filter_metaid_column_name
to filter the query. So my above might not work when it comes to BP.
afaik, bp_filter_metaid_column_name
is used so that quotes in column names are not a problem.
It is called in several functions.
bp-core\bp-core-filters.php > function bp_filter_metaid_column_name
Just looked it up
* Filter SQL query strings to swap out the 'meta_id' column.
*
* 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.
Seems as though it’s used to make WP *_metadata()
functions compatible with BP.