Home › Forums › General Issues › acf/update problem with custom content type › Reply To: acf/update problem with custom content type
Hi @suavedan,
Thanks for the post.
I would recommend you make use of the acf/save_post action instead and then update the post title like so:
//Auto add and update Title field:
function my_post_title_updater( $post_id ) {
$my_post = array();
$my_post['ID'] = $post_id;
$home = get_field("home_team");
$away = get_field("away_team");
$date = get_field("game_date");
$title = $home." @ ".$away." - ".$game_date;
$slug = sanitize_title($title);
$previewdata = array(
'ID' => $post_id,
'post_type' => 'game_preview',
'post_title' => $title,
'post_name' => $slug
);
wp_update_post($previewdata);
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'my_post_title_updater', 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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.