acf_form无法在CPT中发布字段

问题描述

如果我将发布后的状态设置为“发布”(如下所示),则此表单会创建该发布,但是我针对此发布类型的acf字段(某些字段应自动填充)不会添加数据库

如果我将状态设置为“草稿”,则此表单会创建草稿-如果我编辑并保存该草稿,一切都很好

有什么想法吗?

谢谢理查德

<?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对options数组中的fields键的值调用了acf_add_local_field,因此您应该尝试构造数据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]'
    )
),