acf_form 不在 CPT 中发布字段

acf_form not publishing fields in a CPT

如果我将 post-status 设置为 'publish'(如下所示),此表单将创建 post,但我的 acf 字段用于此 post 类型(一些应该自动填充)不会添加到数据库

如果我将 post-status 设置为 'draft',此表单会创建草稿 - 如果我编辑并保存该草稿,一切都很好

有什么想法吗?

谢谢,理查德

<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary" class="rs-add-forms">
    <div id="content" class="site-content" role="main">
    <?php while ( have_posts() ) : the_post(); ?>
    <?php acf_form(array(
        'post_id'       => 'new_post',
        'post_title' => true,
        'new_post'      => array(
            'post_type'     => 'people',
            'post_status'   => 'publish'
        ),
        'fields' => array('field_5ed5c2215be79',), 
        'submit_value'  => 'Create Person',
        'html_submit_button'  => '<input type="submit" class="rs-add-button" value="%s" />',
        
        'updated_message' => false
    )); ?>
    <?php endwhile; ?>
    </div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>

因为 acf_form 调用 acf_add_local_field on the value of the fields key in the options array, you should try structuring your data like the function parses defaults for, internally

// Apply default properties needed for import.
$field = wp_parse_args($field, array(
    'key'       => '',
    'name'      => '',
    'type'      => '',
    'parent'    => '',
));

因此,您可以修改为

'fields' => array(
    array(
        'key' => 'field_5ed5c2215be79',
        'name' => 'Form Field Title',
        'type' => 'registered_acf_fieldtype',
        'parent' => '[probably optional]'
    )
),