Refresh message without header of the update message

I want to update the post data without the refresh header even if the user changes the post header. For this functionality, I write the following codes. But it doesn't work. My code looks like this:

function update_post_without_update_title($post_id,$data) {
      $post = get_post($post_id);
      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
         return;
      if ($data['post_status'] == "publish"){
          $data['post_title'] = $post->post_title;
       }
}

add_action('pre_post_update','update_post_without_update_title',10,2);

      

Can you tell me what to fix here?

Thanks in advance,

+3


source to share


1 answer


Use this function:



 add_action('post_updated','after_update_post_without_update_title',10,3);

 function after_update_post_without_update_title($postId,$after,$before)
 {
        global $wpdb;
        $where = array( 'ID' => $postId );
        $oldTitle = $before->post_title;
        $data = array('post_title'=>$oldTitle);
        $wpdb->update( $wpdb->posts, $data, $where );
        return true;
 }

      

+1


source







All Articles