Hi,
I have a basic front end form set up with a selected field group that saves it’s data into a custom post type, nothing too complicated. However, I’m having an issue generating a post title from a taxonomy term.
Basically, the user can select one term value from a dropdown select list on the form (as well as fill out other fields), then submit the form. I want the post title to reflect the string value of the term, but instead it’s just returning the term ID.
Here’s my code:
functions.php
function my_save_post( $post_id ) {
if ($post_type != 'points') {
return;
}
$taxonomy = $_POST['acf']['field_59940ffa4a644'];
$title = $taxonomy;
$new_post = array(
'ID' => $post_id,
'post_status' => 'publish',
'post_title' => $title,
'post_type' => 'points'
);
remove_action('acf/save_post', 'my_save_post', 20);
wp_update_post( $new_post );
add_action('acf/save_post', 'my_save_post', 20);
}
add_action('acf/save_post', 'my_save_post', 20);
page-template.php
acf_form(
array(
'id' => 'form-points',
'post_id' => 'new_post',
'field_groups' => array(126),
'html_submit_button' => '<input type="submit" class="btn btn-samurai" value="%s" />',
'submit_value' => 'Submit Points',
'updated_message' => 'Points Created Successfully'
)
);
To recap… the form works, but it saves the title of the post as an integer value (the term ID perhaps?), rather than the actual term string value.
Any help would be awesome, thanks in advance!