Home › Forums › ACF PRO › Delete WP Title and use ACF Title › Reply To: Delete WP Title and use ACF Title
I have more than one custom field, so code looks like this:
// Get title from acf into post title
add_action('acf/save_post', 'upd_cust_post_title', 20); // fires after ACF
function upd_cust_post_title($post_id) {
$post_type = get_post_type($post_id);
if ($post_type != 'house') {
return;
}
$post_title = get_field('name', $post_id);
$post_name = sanitize_title($post_title);
$post = array(
'ID' => $post_id,
'post_name' => $post_name,
'post_title' => $post_title
);
wp_update_post($post);
}
add_action('acf/save_post', 'upd_car_post_title', 20); // fires after ACF
function upd_ann_post_title($post_id) {
$post_type = get_post_type($post_id);
if ($post_type != 'car') {
return;
}
$post_title = get_field('title', $post_id);
$post_name = sanitize_title($post_title);
$post = array(
'ID' => $post_id,
'post_name' => $post_name,
'post_title' => $post_title
);
wp_update_post($post);
}
Is that’s the way to do it? Or there’s better way?
Thanks
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.