groups_delete_groupmeta( int $group_id, string|bool $meta_key = false, string|bool $meta_value = false, bool $delete_all = false )

Delete metadata for a group.


Parameters Parameters

$group_id

(int) (Required) ID of the group.

$meta_key

(string|bool) (Optional) The key of the row to delete.

Default value: false

$meta_value

(string|bool) (Optional) Metadata value. If specified, only delete metadata entries with this value.

Default value: false

$delete_all

(bool) (Optional) If true, delete matching metadata entries for all groups. Otherwise, only delete matching metadata entries for the specified group. Default: false.

Default value: false


Top ↑

Return Return

(bool) True on success, false on failure.


Source Source

File: bp-groups/bp-groups-functions.php

function groups_delete_groupmeta( $group_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
	global $wpdb;

	// Legacy - if no meta_key is passed, delete all for the item.
	if ( empty( $meta_key ) ) {
		$table_name = buddypress()->groups->table_name_groupmeta;
		$sql        = "SELECT meta_key FROM {$table_name} WHERE group_id = %d";
		$query      = $wpdb->prepare( $sql, $group_id );
		$keys       = $wpdb->get_col( $query );

		// With no meta_key, ignore $delete_all.
		$delete_all = false;
	} else {
		$keys = array( $meta_key );
	}

	add_filter( 'query', 'bp_filter_metaid_column_name' );

	$retval = true;
	foreach ( $keys as $key ) {
		$retval = delete_metadata( 'group', $group_id, $key, $meta_value, $delete_all );
	}

	remove_filter( 'query', 'bp_filter_metaid_column_name' );

	return $retval;
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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