Updating Custom field on save
-
Hello,
I seem to be having problems getting the code below to work.
Basically I am looking to populate 2 custom fields Year and Month I am getting the date from timestamp but for some reason the only the year is 1970 and month January all the time any ideas?
The code I’am using is below
add_action( 'save_post', 'setMonth'); function setMonth($post_id) { $post = get_the_ID(); $slug = 'cruise-dates'; if ( $slug != $_POST['post_type'] ) { return; } if ( !current_user_can( 'edit_post', $post_id ) ) { return; } $date = get_post_meta($post, 'wpcf-start-date', true); $month = date('F', $date); $year= date("Y",$date); update_post_meta($post_id, 'start_month', $month); update_post_meta($post_id, 'start_year', $year); }
Cheers
Jon
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Updating Custom field on save’ is closed to new replies.