Home
  • Contact
  • Live News
  • Documentation API
  • Function, Filter & Action index
  • Our WordPress plugins
    • Debug Bar Extender
    • WP-Cron-Control
  • Posts

A HitchHackers guide through WordPress

the source for WordPress News, Tips and Help
  • Home
  • Q&A
    • Ask a question
  • Live News
  • Docs
  • Documentation API
  • Contact

update_metadata_by_mid

December 13, 2011 by Thorsten 0 Comments

  • /wp-includes/meta.php(line 385)
  • PHPdoc

Definition:
function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = false ) {}

Update meta data by meta ID

Parameters

  • string $meta_type: Type of object metadata is for (e.g., comment, post, or user)
  • int $meta_id: ID for a specific meta row
  • string $meta_value: Metadata value
  • string $meta_key: Optional, you can provide a meta key to update it

Return values

returns:True on successful update, false on failure.

Defined actions

  • update_{$meta_type}_meta
    do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
  • update_postmeta
    do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
  • updated_{$meta_type}_meta
    do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );

Source code

function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = false ) {

	global $wpdb;



	// Make sure everything is valid.

	if ( ! $meta_type )

		return false;



	if ( ! $meta_id = absint( $meta_id ) )

		return false;



	if ( ! $table = _get_meta_table( $meta_type ) )

		return false;



	$column = esc_sql($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 ) ) {

		$original_key = $meta->meta_key;

		$original_value = $meta->meta_value;

		$object_id = $meta->{$column};



		// If a new meta_key (last parameter) was specified, change the meta key,

		// otherwise use the original key in the update statement.

		if ( false === $meta_key ) {

			$meta_key = $original_key;

		} elseif ( ! is_string( $meta_key ) ) {

			return false;

		}



		// Sanitize the meta

		$_meta_value = $meta_value;

		$meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type );

		$meta_value = maybe_serialize( $meta_value );



		// Format the data query arguments.

		$data = array(

			'meta_key' => $meta_key,

			'meta_value' => $meta_value

		);



		// Format the where query arguments.

		$where = array();

		$where[$id_column] = $meta_id;



		do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );



		if ( 'post' == $meta_type )

			do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );



		// Run the update query, all fields in $data are %s, $where is a %d.

		$result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' );



		// Clear the caches.

		wp_cache_delete($object_id, $meta_type . '_meta');



		do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );

17264

/wp-includes/meta.php, Actions, Actions by letter u, Documentation, Files, Functions, Functions by letter u
idd8572c226bfe74170b87e665cb3250a6, updated_{$meta_type}_meta, update_metadata_by_mid, update_postmeta, update_{$meta_type}_meta

type_url_form_video

December 13, 2011 by Thorsten 0 Comments

  • /wp-admin/includes/deprecated.php
  • PHPdoc

Source code

}

17234

/wp-admin/includes/deprecated.php, Documentation, Files, Functions, Functions by letter t
id77a94112a27943e8996d9dc5479f09c5, type_url_form_video

type_url_form_image

December 13, 2011 by Thorsten 0 Comments

  • /wp-admin/includes/deprecated.php
  • PHPdoc

Source code

}

17231

/wp-admin/includes/deprecated.php, Documentation, Files, Functions, Functions by letter t
idd145e9eced3b507aa5f27d232b80561a, type_url_form_image

type_url_form_file

December 13, 2011 by Thorsten 0 Comments

  • /wp-admin/includes/deprecated.php
  • PHPdoc

Source code

}

17228

/wp-admin/includes/deprecated.php, Documentation, Files, Functions, Functions by letter t
id6d2e6baa2e6fb3bd8c09ec569a3f0119, type_url_form_file

type_url_form_audio

December 13, 2011 by Thorsten 0 Comments

  • /wp-admin/includes/deprecated.php
  • PHPdoc

Source code

}

17225

/wp-admin/includes/deprecated.php, Documentation, Files, Functions, Functions by letter t
id1ba88b076ff4015c28c48c336538adaa, type_url_form_audio
Newer Entries
Older Entries

Ouch, we don’t have this here!

It seems that we do not have anything about this topic here, but you might want to do one of the following. If you were searching for a php function head over to the php manual and use one of their entry points
  • PHP function quick reference
  • PHP Manual
If you were searching for a WordPress related topic and did not find it here try one of the following options.
  • Use the search form in the navigation bar above
  • Use the WordPress search
If nothing like this helps try using Google or an other search engine
  • Google
  • Bing

Golden Q&A rules

Search first

Be sure that you first search in Google, the WordPress forums, Codex or this site ( using the form in the menu ). Sharing your previous results helps narrowing down the problem if you also tell us what you found and why it didn’t serve your needs.

Be specific

Give as much details about your problem as possible. Make sure to include examples, links and context related to your problem.

Be WordPress related

This site focuses on WordPress and related topics. Please make sure that your question is related to WordPress code, functionality or other related topics.

Be nice

Please keep in mind that this is a voluntary service. Answers might not always be correct or what you expect. Please be nice and let us know if any inappropriate answers come to your attention.

Buy us a coffee.

Did you find something that helps you save time or money on this site and just want to say "Thanks". Feel free to buy us a coffee using the button below.

  • Latest
  • Popular
  • Comments
  • Speed up WordPress when you have a lot of terms February 15, 2014
  • WordPress Importer with remote lookup for assets. February 15, 2014
  • It’s been a while! Sorry for neglecting you! September 4, 2013
  • Cache posts in category/tag/taxonomy for better performing content blocks May 10, 2012
  • Lost in time(zones)? http://localtime.at can help May 5, 2012
  • WordPress Syntax mode for Panic Coda February 18, 2011
  • wp_tiny_mce February 12, 2011
  • Initialize WordPress from a PHP CLI script July 22, 2011
  • wp_save_image February 12, 2011
  • Caching WordPress navigation menus – wp_nav_menu() wrapper October 7, 2011
  • Thorsten's avatar Thorsten: Till, that's extra awesome. Especially as I alread...
  • Till Krüss's avatar Till: I just released a WordPress syntax mode for Coda 2...
  • Gift Ideas for Any WordPress Developer… hint hint... | Capstone Creations in Louisville, KY: […] this an all-in-one tool that will improv...
  • madtownlems's avatar madtownlems: Is there any good writeup on how to effectively an...
  • Wordcamp 2013 « David Lomuscio: [...] https://hitchhackerguide.com/2011/02/12/wp_ha...

Categories

RSS WP-Cron.com Links

  • An error has occurred; the feed is probably down. Try again later.

RSS My random code snippets

  • An error has occurred; the feed is probably down. Try again later.

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 2,006 other subscribers

Feed subscriptions

RSS Feed RSS - Posts

RSS Feed RSS - Comments

Latest tweets

Tweets by hitchhacker

Recent Posts

  • Speed up WordPress when you have a lot of terms
  • WordPress Importer with remote lookup for assets.
  • It’s been a while! Sorry for neglecting you!
  • Cache posts in category/tag/taxonomy for better performing content blocks
  • Lost in time(zones)? http://localtime.at can help

A HitchHackers guide through WordPress.

Create a free website or blog at WordPress.com.

  • Subscribe Subscribed
    • A HitchHackers guide through WordPress
    • Join 2,006 other subscribers
    • Already have a WordPress.com account? Log in now.
    • A HitchHackers guide through WordPress
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar