^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 5年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云1核2g仅需102元/年,今日10点开抢

wordpress函数delete_metadata_by_mid()用法示例

delete_metadata_by_mid( string $meta_type,  int $meta_id )

Delete meta data by meta ID


描述


参数

$meta_type

(string)
(Required)
Type of object metadata is for (e.g., comment, post, term, or user).

$meta_id

(int)
(Required)
ID for a specific meta row


返回值

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


源代码

File: wp-includes/meta.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 = intval( $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';

	// Fetch the meta and go on if it's found.
	if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
		$object_id = $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, `$meta_type`, refers to the meta
			 * object type (post or comment).
			 *
			 * @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, `$meta_type`, refers to the meta
			 * object type (post or comment).
			 *
			 * @since 3.4.0
			 *
			 * @param int $meta_ids Deleted metadata entry ID.
			 */
			do_action( "deleted_{$meta_type}meta", $meta_id );
		}

		return $result;

	}

	// Meta id was not found.
	return false;
}

更新日志

Version 描述
3.3.0 Introduced.

相关函数

Uses

  • wp-includes/cache.php:
    wp_cache_delete()
  • wp-includes/formatting.php:
    sanitize_key()
  • wp-includes/plugin.php:
    do_action()
  • wp-includes/wp-db.php:
    wpdb::delete()
  • wp-includes/meta.php:
    _get_meta_table()
  • wp-includes/meta.php:
    get_metadata_by_mid()
  • wp-includes/meta.php:
    delete_{$meta_type}_meta
  • wp-includes/meta.php:
    delete_{$meta_type}meta
  • wp-includes/meta.php:
    deleted_{$meta_type}_meta
  • wp-includes/meta.php:
    deleted_{$meta_type}meta
  • Show 5 more uses
    Hide more uses


Used By

  • wp-admin/includes/ms.php:
    wpmu_delete_user()
  • wp-admin/includes/user.php:
    wp_delete_user()
  • wp-admin/includes/post.php:
    delete_meta()
  • wp-includes/functions.php:
    do_enclose()
  • wp-includes/taxonomy.php:
    wp_delete_term()
  • wp-includes/post.php:
    wp_delete_attachment()
  • wp-includes/post.php:
    wp_delete_post()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::set_custom_fields()
  • wp-includes/comment.php:
    do_all_pings()
  • wp-includes/comment.php:
    wp_delete_comment()
  • Show 5 more used by
    Hide more used by


User Contributed Notes

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈