WordPress filter hook

add_post_metadata

Fired by 4 WordPress plugins, running on 12K+ sites between them.

How to use add_post_metadata

It's a filter: your callback receives the value and 4 more arguments, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'add_post_metadata', function( $value, $postId, $key, $rawValue, $arg5 ) {
	// Change $value here.
	return $value;
}, 10, 5 );

Argument names come from 404 Solution: Redirection and Page Suggestions's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

4 plugins that fire add_post_metadata

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. 404 Solution: Redirection and Page Suggestions icon 404 Solution: Redirection and Page Suggestions10,000+ installs apply_filters( 'add_post_metadata', null, $postId, $key, $rawValue, false ) includes/services/WordPressPostMutationNotifications.php:26
  2. SOOZ icon SOOZ2,000+ installs apply_filters( 'add_post_metadata', null, $attachment_post_id, $meta_key, $hook_value, false ) includes/core/attachments-media.php:2921
  3. Sage Page Builder icon Sage Page BuilderFewer than 10 installs apply_filters( 'add_post_metadata', null, $post_id, $backup_key, $backup, false ) includes/class-layout-storage.php:206
  4. JonnyAD SEO icon JonnyAD SEOFewer than 10 installs apply_filters( 'add_post_metadata', null, $post_id, $key, $to, true ) includes/admin.php:1476

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.