Home › Forums › ACF PRO › Create product title + permalink + slug from several custom fields › Reply To: Create product title + permalink + slug from several custom fields
Hi @stockholm
I think you need something like the below:
<?php
add_action( 'transition_post_status', 'acf_generate_custom_url', 10, 3 );
function acf_generate_custom_url( $new_status, $old_status, $post ) {
#only apply this to a particular post type
if ( 'publish' !== $new_status or 'publish' === $old_status || 'product' !== get_post_type( $post ) )
return;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
#get custom fields
$field_1 = get_field('field_1');
$field_2 = get_field('field_2');
$field_3 = get_field('field_3');
#join field data
$new_permalink = $field_1.' '.$field_2.' '.$field_3; #you can remove the space if you need
#get the post data
$my_post = array(
'ID' => $post->ID,
'post_title' => $new_permalink, #update title
'post_name' => $new_permalink #update slug
);
#update the post into the database
wp_update_post( $my_post );
}
Code is untested but should get you pretty close
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.