I’ve created a function to change the post title and post name using fields from a frontend form for a given custom post type.
add_action('acf/save_post', 'chiwp_update_post_name', 20);
$desired_url = get_field('show_information', $post_id);
$desired_url = $desired_url['desired_url_extension'];
$title = get_field('show_information', $post_id);
$title = $title['show_name'];
$data = array(
'ID' => $post_id,
'post_title' => $title,
'post_name' => sanitize_title($desired_url),
This function correctly updates the data as it should, however, there is an issue with saving. When I view the post preview in the admin, it displays the page as if no fields have been entered. Yet, The actual admin page shows that all of the field data is there, so we know the form works properly.
If I simply click ‘save draft’ and then view the draft, everything displays properly.
I think I just need to make sure the updated fields save as a draft AFTER updating. I’ve tried adjusting the priority, from
5 but that doesn’t seem to work.
Here is the form:
$fields = array(
'id' => 'new-things',
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'things',
'post_status' => 'draft',
'post_title' => false,
'post_content' => false,
'uploader' => 'basic',
'return' => home_url('/'),
'fields' => $fields,
'submit_value' => 'Submit the thing'
Any ideas with this one? Thanks!