Home Forums ACF PRO ACF_Form Generate Post Title Reply To: ACF_Form Generate Post Title

  • You need to create either an acf/pre_save_post or an acf/save_post filter. Since you’re using the built in acf/pre_save_post filter I would go with an acf/save_post filter.

    add_action('acf/save_post', 'update_setups_2019_title');
    function update_setups_2019_title($post_id) {
      if (get_post_type($post_id) != 'update_setups_2019') 
        // only run on your post type
      // get the post
      $post = get_post($post_id);
      // update the post title
      $post->post_title = get_field('field-one').' '.get_field('field-two'); // etc..
      // correct the slug.. optional and I don't know that this is 100% correct
      $slug = sanitize_title($post->title);
      $post->post_name = wp_unique_post_slug($slug, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
      // remove this filter to prevent infinite loop
      remove_filter('acf/save_post', 'update_setups_2019_title');
      // update the post
      // re-add this filter
      add_action('acf/save_post', 'update_setups_2019_title');