【问题标题】:acf_form not publishing fields in a CPTacf_form 未在 CPT 中发布字段
【发布时间】:2020-08-23 16:14:07
【问题描述】:

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

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

有什么想法吗?

谢谢,理查德

<?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(); ?>

【问题讨论】:

    标签: wordpress advanced-custom-fields custom-post-type


    【解决方案1】:

    由于acf_form 在选项数组中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]'
        )
    ), 
    

    【讨论】:

    • 感谢 Cameron,这听起来很有希望,但我对数组感到困惑 'fields' =&gt; array('field_5ed5c2215be79',), 是一个不同字段的数组,但您将它显示为一个字段的不同元素的数组跨度>
    • 这是有道理的,除了我有需要“初始化”的字段但我不希望它们显示在表单中。有没有办法做到这一点?
    • 隐藏输入类型,不是吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 2018-06-18
    • 1970-01-01
    相关资源
    最近更新 更多