• This excellent code snippet from matotominac will “Automatically set WordPress post title on save“. But it doesn’t update the title when I first create the post. I’m not sure where to look. Any suggestions?

    <?php
    add_filter('wp_insert_post_data', function($data, $id) {
        // Check for the correct post type
        if ($data['post_type'] == 'newsletter') {
                // Month
                $field = get_field_object('issue_month');
                $month_slug = $field['key'];
                // Year
                $field = get_field_object('issue_year');
                $year_slug = $field['key'];
                // Issue Number
                $field = get_field_object('issue_number');
                $issue_slug = $field['key'];
     
            $data['post_title'] = $_POST['acf'][$month_slug] . " " . $_POST['acf'][$year_slug] . " / Issue " . $_POST['acf'][$issue_slug];
        }
     
        return $data;
    }, 10, 2);

The topic ‘Title from two fields almost works’ is closed to new replies.