Advertisement
idotherest34

Untitled

Oct 25th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. add_action('cred_save_data', 'my_save_data_action',10,2);
  2. function my_save_data_action($post_id, $form_data)
  3. {
  4.     // Change your Form ID
  5.     if ($form_data['id']==280)
  6.  
  7.     {
  8.          //Declare the content of your variables
  9.         $custom_title = get_post_meta( $post_id, 'wpcf-firstnamecpt' , true );
  10.         $custom_title.= ' ';
  11.         $custom_title.= get_post_meta($post_id, 'wpcf-last-namecpt', true) ;
  12. //adding to post_meta because function only appears to take 1 value.
  13.         //collect data and define new title
  14.         $my_post = array(
  15.             'ID'           => $post_id,
  16.             'post_title'   => $custom_title,
  17.  
  18.         );
  19.  
  20.         // Update the post into the database
  21.         wp_update_post( $my_post );
  22.  
  23.     }
  24. }
  25. //added cred hook to change post title for cred forms from now on.
  26.  
  27. add_action('cred_save_data','combined_title', 10, 2);
  28. function combined_title($post_id, $form_data) {
  29. // if a specific form
  30. if ($form_data['id']==280) {
  31.     $type = get_post_type($post_id, $form_data);
  32.     if ($type == 'staff-member')
  33.     {
  34.         $wpt_intranet_smslug = get_post_meta($post_id, 'wpcf-firstnamecpt', true); //variable declared to hold post ID and fields
  35.         $wpt_intranet_smslug .= get_post_meta($post_id, 'wpcf-last-namecpt', true) ;
  36.         $key = $wpt_intranet_smslug . '-' . $post_id;
  37.         $slug = sanitize_title($key);
  38.         wp_update_post(array('ID' => $post_id, 'post_title' => $key, 'post_name' => $slug));
  39.     }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement