bedas

Update Post Title + Slug by value from custom field

May 24th, 2015
1,025
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function my_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_title = get_post_meta( $post_id, 'wpcf-your_custom_field_slug', true );
  7.                
  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', 'my_save_data_action',10,2);
RAW Paste Data