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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.