Home › Forums › ACF PRO › Add a custom field to post permalink › Reply To: Add a custom field to post permalink
Hello John,
is it correct that I need to save the Post twice to the the SLUG changed?
Or am I doing something wrong?
function modify_post_slug($post_id) {
$artist = get_field('artist', $post_id);
$album = get_field('album', $post_id);
$datum = get_field('datum', $post_id);
$ref = $artist.' '.$album.' '.$datum;
if ($ref) {
$post = get_post($post_id);
$slug = sanitize_title($ref);
$post->post_name = $slug;
remove_filter('acf/save_post', 'modify_post_slug');
wp_update_post($post);
add_action('acf/save_post', 'modify_post_slug');
}
}
add_action('acf/save_post', 'modify_post_slug');
Cheers,
Denis
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.