bp_messages_delete_meta( int $message_id, string|bool $meta_key = false, string|bool $meta_value = false, bool $delete_all = false )

Delete metadata for a message.


If $meta_key is false, this will delete all meta for the message ID.

See also



(int) (Required) ID of the message to have meta deleted for.


(string|bool) (Optional) Meta key to delete.

Default value: false


(string|bool) (Optional) Meta value to delete.

Default value: false


(bool) (Optional) Whether or not to delete all meta data.

Default value: false


(bool) True on successful delete, false on failure.


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

function bp_messages_delete_meta( $message_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
	// Legacy - if no meta_key is passed, delete all for the item.
	if ( empty( $meta_key ) ) {
		global $wpdb;

		$keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->messagemeta} WHERE message_id = %d", $message_id ) );

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

	$retval = false;

	// No keys, so stop now!
	if ( empty( $keys ) ) {
		return $retval;

	add_filter( 'query', 'bp_filter_metaid_column_name' );

	foreach ( $keys as $key ) {
		$retval = delete_metadata( 'message', $message_id, $key, $meta_value, $delete_all );

	remove_filter( 'query', 'bp_filter_metaid_column_name' );

	return $retval;


Version Description
BuddyPress 2.2.0 Introduced.


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.