Home › Forums › ACF PRO › Using ACF fields to setup a post title › Reply To: Using ACF fields to setup a post title
I’ve managed to get it working by retrieving fields values from the POST request.
function show_update_postdata( $value, $post_id, $field ) {
// Get values from POST
$date = strtotime($_POST['acf']['field_595cf97c444c0']);
$band = get_the_title($_POST['acf']['field_595cfa314cf4b']);
$country = $_POST['acf']['field_595cf99f444c1'];
$city = $_POST['acf']['field_595cf9f1444c2'];
// Custom post title
$formatted_date = date_i18n('F jS, Y', $date);
$title = $band . ' @ ' . $city . ', ' . $country . ' - ' . $formatted_date;
$slug = sanitize_title( $title );
$postdata = array(
'ID' => $post_id,
'post_title' => $title,
'post_type' => 'show',
'post_name' => $slug
);
wp_update_post( $postdata );
return $value;
}
add_filter('acf/update_value/name=date', 'show_update_postdata', 10, 3);
add_filter('acf/update_value/name=band', 'show_update_postdata', 10, 3);
add_filter('acf/update_value/name=city', 'show_update_postdata', 10, 3);
add_filter('acf/update_value/name=country', 'show_update_postdata', 10, 3);
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.