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’.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.