Home › Forums › General Issues › Populate acf_form title with taxonomy term value › Reply To: Populate acf_form title with taxonomy term value
Hey shanekins,
You seem to be pretty close with this.. assuming that the dropdown you have created is returning the term ID, all you need to do is use the built in WordPress function ‘get_term’ to get the taxonomy’s name:
function my_save_post( $post_id ) {
// Pull the Term ID from the form:
$term_id = $_POST['acf']['field_59940ffa4a644'];
// Now get the WordPress term Object:
$term = get_term( $term_id );
// Check to see that a term is returned successfully
if ( ! empty( $term && ! is_wp_error( $term ) ) )
{
// Now you can get the term name for your title
$title = $term->name;
$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);
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.