Home › Forums › Feature Requests › Set 'Post Title' from Field Group (Toggle) › Reply To: Set 'Post Title' from Field Group (Toggle)
Hi all,
This has been really useful for me. I’ve been trying to find a way to use an ACF field as a CPT title and this works nicely for me
`* add custom slug and title */
function my_post_title_updater( $post_id ) {
if ( get_post_type( $post_id ) == ‘venue’ ) {
$my_post = array();
$my_post[‘ID’] = $post_id;
$my_post[‘post_title’] = get_field( ‘venue_name’, $post_id );
wp_update_post( $my_post );
}
}
// run after ACF saves the $_POST[‘fields’] data
add_action(‘acf/save_post’, ‘my_post_title_updater’, 20);
A couple of quick questions …
How can I concatenate two variables so that I can use ‘venue_name’ and ‘venue_city’?
Also, how can I expand this to update the slug to use the same title ‘venue_name’ and ‘venue_city’? I currently have http://localhost:8888/gigs/venue/auto-draft/ as the slug.
Thanks all.
Cheers
Phil
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.