Support

Account

Home Forums ACF PRO Add a custom field to post permalink Reply To: Add a custom field to post permalink

  • @hube2

    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