Save custome field and use it as post date
-
Hi all,
I found a neat script that takes the date of a custom field and saves it as the post’s date:function change_post_date( $post_id, $post ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return; if ( false !== wp_is_post_revision( $post_id ) ) return; if ( ! current_user_can( 'edit_post', $post_id ) ) return; $date_time_field = get_post_meta($post_id, 'datum', true); remove_action('save_post', 'change_post_date', 10); $args = array ( 'ID' => $post_id, 'post_date' => $date_time_field, 'post_date_gmt' => gmdate('Y-m-d H:i', $date_time_field ) ); wp_update_post( $args ); add_action('save_post', 'change_post_date', 10); } add_filter('save_post', 'change_post_date', 10, 2);
This works fine, but not in one go. The post date is saved before the custom field, so it would only use the newly entered date on a second save. This is logical, but is there a way around that? Can I save that specific custom date field before I call it via get_post_meta ?
I am grateful for any input, since I am no “real” programmer ??
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Save custome field and use it as post date’ is closed to new replies.