Advertisement
Beee

acf/pre_save_post

Sep 20th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. function my_pre_save_post( $post_id )
  2. {
  3.     global $wpdb;
  4.     $entered_title  = $_POST['acf']['field_57dec9df66a5b'];
  5.     $cleaned_title  = preg_replace('/[^A-Za-z0-9\-\s]/', '', $entered_title); // Removes special chars.
  6.     $post_name      = sanitize_title($cleaned_title);
  7.  
  8.     // check if this is to be a new post
  9.     if ( $post_id != 'new_post' )
  10.     {
  11.         // return $post_id;
  12.     }
  13.  
  14.     $wpdb->update( $wpdb->posts, array( 'post_title' => $cleaned_title, 'post_name' => $post_name ), array( 'ID' => $post_id ) );
  15.     update_field('field_57dec9df66a5b', $cleaned_title, $post_id);
  16.  
  17.     $to             = get_option('admin_email');
  18.     $subject        = 'New submission';
  19.     $message        = 'This is the message body';
  20.     $headers[]      = 'From: Us <support@us.nl>';
  21.     $headers[]      = 'Content-Type: text/html; charset=UTF-8';
  22.  
  23.     // return the same ID
  24.     return $post_id;
  25. }
  26. add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement