The action sends the $post_id
just like you have so that’s not the problem.
Have you tried a var_dump
of $_POST
to make sure it’s actually posting something other than null?
Also, using the save_post
action is going to be called every time a post is saved, so you probably need to use the save_post_{custom_post_type}
action, replacing {custom_post_type}
with your actual custom post type (if it is one).
You could try this:
function process_image_meta( $post_id, $post ) {
error_log('POSTED: ' . $_POST['upload_image_id']);
$result = update_post_meta( $post_id, '_image_id', $_POST['upload_image_id'] );
error_log('Image Meta Added: ' . $result);
}
Make sure you have this in your wp-config.php
:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Then check the /wp-content/debug.log
file for the output