bp_blogs_delete_blogmeta( int $blog_id, string|bool $meta_key = false, string|bool $meta_value = false, bool $delete_all = false )

Delete a metadata from the DB for a blog.

Parameters Parameters


(int) (Required) ID of the blog whose metadata is being deleted.


(string|bool) (Optional) The key of the metadata being deleted. If omitted, all BP metadata associated with the blog will be deleted.

Default value: false


(string|bool) (Optional) If present, the metadata will only be deleted if the meta_value matches this parameter.

Default value: false


(bool) (Optional) If true, delete matching metadata entries for all objects, ignoring the specified blog_id. Otherwise, only delete matching metadata entries for the specified blog. Default: false.

Default value: false

Top ↑

Return Return

(bool) True on success, false on failure.

Source Source

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

function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
	global $wpdb;

	// Legacy - if no meta_key is passed, delete all for the blog_id.
	if ( empty( $meta_key ) ) {
		$table_name = buddypress()->blogs->table_name_blogmeta;
		$sql        = "SELECT meta_key FROM {$table_name} WHERE blog_id = %d";
		$query      = $wpdb->prepare( $sql, $blog_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' );
	add_filter( 'sanitize_key', 'bp_blogs_filter_meta_column_name' );

	$retval = false;
	foreach ( $keys as $key ) {
		$retval = delete_metadata( 'bp_blog', $blog_id, $key, $meta_value, $delete_all );

	remove_filter( 'query', 'bp_filter_metaid_column_name' );
	remove_filter( 'sanitize_key', 'bp_blogs_filter_meta_column_name' );

	return $retval;

Top ↑

User Contributed Notes User Contributed Notes

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