I'm trying to reformat the date entered into a custom field called event_date_begin so that it's in a standard format when the post is published. Every related bit of information I can find says to hook into the save_post action and retrieve existing custom field values with $_POST['custom field name']. Yet I always find this has no contents, even though I know this custom field exists. This is in my functions.php file:
add_action('save_post', 'update_dates');
function update_dates ($ID = false, $post = false) {
if (isset($_POST['event_date_begin']))
update_post_meta($ID, 'event_date_begin', date('Y/m/d', strtotime($_POST['event_date_begin'])));
else
update_post_meta($ID, 'event_date_begin', 'empty');
}
This always sets rewrites the event_date_begin custom field to “empty” (the else clause here is just for testing).
I even once put in code to check $_POST['event_date_begin'] right after setting it to the 'empty' value, and it still fails the isset() test.
I can’t find anyone else saying $_POST is empty when it shouldn’t be, so I can’t figure out why it’s always empty for me. This is when I update a post (as opposed to a page, which I haven’t tested).