bedas

Update Post Title + Slug with Timestamp converted to Date

Jun 2nd, 2015
323
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ttd_save_data_action($post_id, $form_data){
  2.             // Change your CRED Form "ID" accordingly below
  3.             if ($form_data['id']==ID){
  4.                
  5.                 //Declare the content of your variables, change "your_custom_field_slug" accordingly
  6.                 $custom_value = get_post_meta( $post_id, 'wpcf-your_custom_field_slug', true );//get posts' Date field value (timestamp)
  7.                 $custom_title = gmdate("m-d-Y", $custom_value);//convert timestamp to m-d-y for output
  8.                 //collect data and define new title
  9.                 $my_post = array(
  10.                     'ID'               => $post_id,
  11.                     'post_title'   => $custom_title,
  12.                     'post_name' => $custom_title,
  13.                    
  14.                 );
  15.                
  16.                 // Update the post into the database
  17.                 wp_update_post( $my_post );
  18.                
  19.             }
  20.         }
  21.     add_action('cred_save_data', 'ttd_save_data_action',10,2);
RAW Paste Data