Support

Account

Home Forums General Issues How to change 'post_status' and 'meta_input' of already created post? Reply To: How to change 'post_status' and 'meta_input' of already created post?

  • Thanks for the answer. Everything worked, only with acf/pre_save_post, not acf/save_post.
    The code from the functions.php

    function my_pre_save_post($post_id) {
      
        if (!is_numeric($post_id) || get_post_type($post_id) != 'task') {
        return $post_id;
        }
    	global $current_user;
        wp_get_current_user();
    	$userid = $current_user->ID;
        $post = array(
        	'ID' => $post_id,
        	'post_status'  => 'inwork' ,
        	'meta_input' => array('task_worker' => $userid, 'task_result' => ''),
        );  
    
        $post_id = wp_insert_post($post); 
        wp_update_post($post);
        
        return $post_id;
      }
      
      add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );

    Prompt, and how to make if buttons two? The button whose code is given above changes ‘post_status ‘to’ inwork ‘and’ meta_input ‘ to the current user id. The other button should change ‘post_status’ to ‘pending’.