Home › Forums › Front-end Issues › Set Post Status and Post Parent via custom field › Reply To: Set Post Status and Post Parent via custom field
Hi @maxaud
In that case, you need to create dummy custom fields to create the form. You can also add the input fields manually using “html_after_fields” option, but it will be more complex.
For the post status, you can create a select field type while for the parent post, you can use a post object field type. After that, you can update the post using the acf/save_post and wp_update_post() function. Maybe something like this:
function my_acf_save_post( $post_id ) {
// Get the selected post status
$value = get_field('post_status_field', $post_id);
// Update current post
$my_post = array(
'ID' => $post_id,
'post_status' => $value,
);
// Remove the action to avoid infinite loop
remove_action('acf/save_post', 'my_acf_save_post', 20);
// Update the post into the database
wp_update_post( $my_post );
// Add the action back
add_action('acf/save_post', 'my_acf_save_post', 20);
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
Hope this helps 🙂
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.