Support

Account

Home Forums Backend Issues (wp-admin) Set post publish date by custom field? Reply To: Set post publish date by custom field?

  • I found the solution with wp_update_post().

    
    add_action('save_post', 'change_content');
        global $post;
        global $wpdb;
        function change_content($post_id) {
    	$datefield = get_post_meta($post_id,'acf-event-date',true);
    	$post_date = date("Y-m-d H:i:s", strtotime($datefield));
    	$my_post = array();
    	$my_post['ID'] = $post_id;
    	$my_post['post_date'] = $post_date;
    	
    	remove_action('save_post', 'change_content');
            wp_update_post( $my_post );
    	add_action('save_post', 'change_content');
    }
    	
    

    Davelee