# delete_metadata_by_mid()

URL: https://chugunov.pro/api-wordpress/functions/delete_metadata_by_mid/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 3.3.0.

## Сигнатура

```php
delete_metadata_by_mid( string $meta_type, int $meta_id ): bool
```

## Описание

Удаляет метаданные по ID метаданных.

## Параметры

- `$meta_type` `string` — обязательный. Тип объекта, к которому относятся метаданные. Принимает 'blog', 'post', 'comment', 'term', 'user' или любой другой тип объекта со связанной таблицей метаданных.
- `$meta_id` `int` — обязательный. ID конкретной строки метаданных.

## Возвращаемое значение

`bool`

## Исходный код

Файл: `wp-includes/meta.php:1013`

```php
function delete_metadata_by_mid( $meta_type, $meta_id ) {
	global $wpdb;

	// Make sure everything is valid.
	if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
		return false;
	}

	$meta_id = (int) $meta_id;
	if ( $meta_id <= 0 ) {
		return false;
	}

	$table = _get_meta_table( $meta_type );
	if ( ! $table ) {
		return false;
	}

	// Object and ID columns.
	$column    = sanitize_key( $meta_type . '_id' );
	$id_column = ( 'user' === $meta_type ) ? 'umeta_id' : 'meta_id';

	/**
	 * Short-circuits deleting metadata of a specific type by meta ID.
	 *
	 * The dynamic portion of the hook name, `$meta_type`, refers to the meta object type
	 * (blog, post, comment, term, user, or any other type with an associated meta table).
	 * Returning a non-null value will effectively short-circuit the function.
	 *
	 * Possible hook names include:
	 *
	 *  - `delete_blog_metadata_by_mid`
	 *  - `delete_post_metadata_by_mid`
	 *  - `delete_comment_metadata_by_mid`
	 *  - `delete_term_metadata_by_mid`
	 *  - `delete_user_metadata_by_mid`
	 *
	 * @since 5.0.0
	 *
	 * @param null|bool $delete  Whether to allow metadata deletion of the given type.
	 * @param int       $meta_id Meta ID.
	 */
	$check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id );
	if ( null !== $check ) {
		return (bool) $check;
	}

	// Fetch the meta and go on if it's found.
	$meta = get_metadata_by_mid( $meta_type, $meta_id );
	if ( $meta ) {
		$object_id = (int) $meta->{$column};

		/** This action is documented in wp-includes/meta.php */
		do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );

		// Old-style action.
		if ( 'post' === $meta_type || 'comment' === $meta_type ) {
			/**
			 * Fires immediately before deleting post or comment metadata of a specific type.
			 *
			 * The dynamic portion of the hook name, `$meta_type`, refers to the meta
			 * object type (post or comment).
			 *
			 * Possible hook names include:
			 *
			 *  - `delete_postmeta`
			 *  - `delete_commentmeta`
			 *
			 * @since 3.4.0
			 *
			 * @param int $meta_id ID of the metadata entry to delete.
			 */
			do_action( "delete_{$meta_type}meta", $meta_id );
		}

		// Run the query, will return true if deleted, false otherwise.
		$result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) );

		// Clear the caches.
		wp_cache_delete( $object_id, $meta_type . '_meta' );

		/** This action is documented in wp-includes/meta.php */
		do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );

		// Old-style action.
		if ( 'post' === $meta_type || 'comment' === $meta_type ) {
			/**
			 * Fires immediately after deleting post or comment metadata of a specific type.
			 *
			 * The dynamic portion of the hook name, `$meta_type`, refers to the meta
			 * object type (post or comment).
			 *
			 * Possible hook names include:
			 *
			 *  - `deleted_postmeta`
			 *  - `deleted_commentmeta`
			 *
			 * @since 3.4.0
			 *
			 * @param int $meta_id Deleted metadata entry ID.
			 */
			do_action( "deleted_{$meta_type}meta", $meta_id );
		}

		return $result;

	}

	// Meta ID was not found.
	return false;
}
```

## История изменений

- 3.3.0 — Introduced.

## Связанные

Использует: [`wp_cache_delete`](https://chugunov.pro/api-wordpress/functions/wp_cache_delete/), `wpdb::delete`, [`_get_meta_table`](https://chugunov.pro/api-wordpress/functions/_get_meta_table/), [`get_metadata_by_mid`](https://chugunov.pro/api-wordpress/functions/get_metadata_by_mid/), [`sanitize_key`](https://chugunov.pro/api-wordpress/functions/sanitize_key/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/).
Используется в: [`wp_delete_site`](https://chugunov.pro/api-wordpress/functions/wp_delete_site/), `wp_xmlrpc_server::set_term_custom_fields`, [`wpmu_delete_user`](https://chugunov.pro/api-wordpress/functions/wpmu_delete_user/), [`wp_delete_user`](https://chugunov.pro/api-wordpress/functions/wp_delete_user/), [`delete_meta`](https://chugunov.pro/api-wordpress/functions/delete_meta/), [`do_enclose`](https://chugunov.pro/api-wordpress/functions/do_enclose/), [`wp_delete_term`](https://chugunov.pro/api-wordpress/functions/wp_delete_term/), [`wp_delete_attachment`](https://chugunov.pro/api-wordpress/functions/wp_delete_attachment/), [`wp_delete_post`](https://chugunov.pro/api-wordpress/functions/wp_delete_post/), `wp_xmlrpc_server::set_custom_fields`, [`wp_delete_comment`](https://chugunov.pro/api-wordpress/functions/wp_delete_comment/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/delete_metadata_by_mid/
