wordpress - Change publish date from meta date when publish post -


when post publish, want publish date same date in meta data, imic_sermon_date.

here's code. problem stuck when publishing post.

function update_sermon_date ($post_id) {     //automatically change publish date sermon date when publish/save postfunction update_sermon_date ($post_id) {     $sermon_date = get_post_meta($post_id, 'imic_sermon_date', true);     $mypost = array (         'id' => $post_id,         'post_date' => $sermon_date);     wp_update_post( $mypost );     }      add_action ('save_post', 'update_sermon_date'); 

can me this?

thanks.

after searching online, i've fixed code.

the code update when post edited. added remove_action , add_action in order prevent code running endless loop.

****//automatically change publish date sermon date when publish/save post function update_sermon_date () {     if (defined('doing_autosave') && doing_autosave)         return;       if ( !current_user_can('edit_post', $post_id) )         return;      $sermon_date = get_post_meta(get_the_id(), 'imic_sermon_date', true);      $mypost = array (         'id' => get_the_id(),         'post_title' => $sermon_date,         'post_date' => $sermon_date,         'post_date_gmt' => $sermon_date);      if ( ! (wp_is_post_revision($post_id) || wp_is_post_autosave ( $post_id) ) ) {         remove_action('edit_post','update_sermon_date');         wp_update_post( $mypost );     add_action ('edit_post', 'update_sermon_date');     } }  add_action ('edit_post', 'update_sermon_date');**** 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -