Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // UPDATE: this code is working. Just FYI if you come across this link through https://support.advancedcustomfields.com/forums/topic/save-edited-post-as-pending-add-acf-field-title/
- function change_post_status() {
- if ( isset($_GET['ad']) ) {
- $post_id = $_GET['ad'];
- } else {
- $post_id = $post_id;
- }
- $site_url = site_url();
- global $wpdb;
- if ( ! $post = get_post( $post_id ) ) {
- return;
- }
- if ( 'pending' == $post->post_status ) {
- return;
- } else { // is post != pending
- $entered_title = $_POST['acf']['field_57dec9df66a5b'];
- $cleaned_title = preg_replace('/[^A-Za-z0-9\-\s]/', '', $entered_title); // Removes special chars.
- // Update DB with pending status.
- $wpdb->update( $wpdb->posts, array( 'post_status' => 'pending', 'post_title' => $cleaned_title ), array( 'ID' => $post_id ) );
- update_field('field_57dec9df66a5b', $cleaned_title, $post_id);
- // send email
- $to = get_option('admin_email');
- $subject = 'Published ad is edited';
- $headers[] = 'From: DVP Portal <support@dvp.nl>';
- $headers[] = 'Content-Type: text/html; charset=UTF-8';
- $message = '<a href="'. $site_url .'/wp-admin/post.php?post='. $post_id .'&action=edit">Klik hier voor de ad</a>';
- wp_mail( $to, $subject, $message, $headers );
- // clean the cache for the post
- clean_post_cache( $post->ID );
- // Trigger all transition hooks in wordpress (in case other functions hook into those to do things.
- $old_status = $post->post_status;
- $post->post_status = 'pending';
- wp_transition_post_status( 'publish', $old_status, $post );
- }
- }
- add_action('acf/save_post', 'change_post_status', 20);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement