如何在acf表单前端添加acf表单postclary字段,但不显示类别下拉列表

时间:2017-05-22 12:11:58

标签: php wordpress advanced-custom-fields

前端没有显示类别下拉列表。请在我的代码中建议或告诉我错误的地方。

   <?php  acf_form(array(
                'post_id'       => 'new_post',
                'post_title'    => true,
                'post_content'  => true,
                'post_category' => true,
                'field_groups' => array('group_57d9928ba5858'),
                'new_post'      => array(
                    'post_type'     => 'festival',
                    'post_status'   => 'draft'
                ),
                'submit_value'       => 'Submit Post',
                'updated_message'    => 'Saved!',
                    'uploader'           => 'wp',
            ));?>

3 个答案:

答案 0 :(得分:0)

我无法在https://www.advancedcustomfields.com/resources/acf_form/中看到post_category作为选项,我认为它应该在

'new_post' => array(
     'post_type' => 'foo',
     'post_status' => 'publish',
     'post_category' => array ('bar')
),

答案 1 :(得分:0)

ACF不会自动将类别选项添加到前端表单。最好的解决方案是设置一个引用类别分类(“分类字段类型”)的自定义字段,并将“添加术语”,“保存术语”和“加载术语”值设置为true,以便该字段像本机类别字段一样工作。

或者,您可以将以下代码添加到由ACF生成PHP工具针对我用这些设置设置的字段生成的函数文件中。


if( function_exists('acf_add_local_field_group') ) {
acf_add_local_field_group(array(
    'key' => 'group_5dc382838casdf',
    'title' => 'Category',
    'fields' => array(
            array(
            'key' => 'field_5ddcdd3232asD',
            'label' => 'Category',
            'name' => 'category',
            'type' => 'taxonomy',
            'instructions' => '',
            'required' => 1,
            'conditional_logic' => 0,
            'wrapper' => array(
                'width' => '',
                'class' => '',
                'id' => '',
            ),
            'taxonomy' => 'category',

            // Accepts SINGLE VALUE: radio, select, MULTIPLE VALUES: multi_select, checkbox
            'field_type' => 'multi-select', 
            'allow_null' => 0,

            // Ensures taxonomy relationships are set on add, save, load
            'add_term' => 1,
            'save_terms' => 1,
            'load_terms' => 1,

            'return_format' => 'id',
            'multiple' => 0,

            // Form Placeholder
            'placeholder' => 'Select Topics'
        )
    ),
    'location' => array(
        array(
            array(
                'param' => 'post_type',
                'operator' => '==',

                // ADD YOUR POST-TYPE HERE
                'value' => 'post',
            ),
        ),
    ),
    'menu_order' => 0,
    'position' => 'normal',
    'style' => 'default',
    'label_placement' => 'top',
    'instruction_placement' => 'label',
    'hide_on_screen' => '',
    'active' => true,
    'description' => '',
));    
}

答案 2 :(得分:0)

这是有效的...

function acf_xyz_categories( $value, $post_id, $field  ){ 
    if($value != ''){
        $valueint = array_map('intval', $value);
$set_taxonomy_ids = wp_set_object_terms( $post_id, $valueint, 'your_taxonomy_name', true );
    }
    return $value;
}
add_filter('acf/update_value/name=abc_category', 'acf_xyz_categories', 10, 3);