Support

Account

Home Forums ACF PRO Using ACF fields to setup a post title Reply To: Using ACF fields to setup a post title

  • I’ve managed to get it working by retrieving fields values from the POST request.

    function show_update_postdata( $value, $post_id, $field ) {
    
            // Get values from POST
            $date = strtotime($_POST['acf']['field_595cf97c444c0']);
            $band = get_the_title($_POST['acf']['field_595cfa314cf4b']);
            $country = $_POST['acf']['field_595cf99f444c1'];
            $city = $_POST['acf']['field_595cf9f1444c2'];
    
            // Custom post title
            $formatted_date = date_i18n('F jS, Y', $date);
            $title = $band . ' @ ' . $city . ', ' . $country . ' - ' . $formatted_date;
            $slug = sanitize_title( $title );
            $postdata = array(
                 'ID'          => $post_id,
                 'post_title'  => $title,
                 'post_type'   => 'show',
                 'post_name'   => $slug
            );
    
            wp_update_post( $postdata );
            return $value;
    
    }
    add_filter('acf/update_value/name=date', 'show_update_postdata', 10, 3);
    add_filter('acf/update_value/name=band', 'show_update_postdata', 10, 3);
    add_filter('acf/update_value/name=city', 'show_update_postdata', 10, 3);
    add_filter('acf/update_value/name=country', 'show_update_postdata', 10, 3);