注册字段与PHP acf无法正常工作

时间:2018-01-22 07:58:01

标签: php wordpress advanced-custom-fields

我想在我的ACF插件中创建自定义字段,但使用PHP。 所以我尝试了以下功能,但没有任何反应,任何人都可以帮助我

function register_custom_acf_fields() {
if ( function_exists( 'acf_add_local_field_group' ) ) {
    // ACF Group: People
    acf_add_local_field_group( array (
        'key'      => 'group_person_details',
        'title'    => 'Person Details',
        'location' => array (
            array (
                array (
                    'param'    => 'post_type',
                    'operator' => '==',
                    'value'    => 'person',
                ),
            ),
        ),
        'menu_order'            => 0,
        'position'              => 'normal',
        'style'                 => 'default',
        'label_placement'       => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen'        => '',
    ) );
    // First name
    acf_add_local_field( array(
        'key'          => 'field_first_name',
        'label'        => 'First Name',
        'name'         => 'first_name',
        'type'         => 'text',
        'parent'       => 'group_person_details',
        'instructions' => '',
        'required'     => 1,
    ) );
    // Middle name
    acf_add_local_field( array(
        'key'          => 'field_middle_name',
        'label'        => 'Middle Name',
        'name'         => 'middle_name',
        'type'         => 'text',
        'parent'       => 'group_person_details',
        'instructions' => '',
        'required'     => 0,
    ) );
    // Last name
    acf_add_local_field( array(
        'key'          => 'field_last_name',
        'label'        => 'Last Name',
        'name'         => 'last_name',
        'type'         => 'text',
        'parent'       => 'group_person_details',
        'instructions' => '',
        'required'     => 1,
    ) );
    // Image
    acf_add_local_field( array(
        'key'           => 'field_image',
        'label'         => 'Image',
        'name'          => 'image',
        'type'          => 'image',
        'parent'        => 'group_person_details',
        'instructions'  => '',
        'required'      => 0,
        'return_format' => 'array',
        'preview_size'  => 'thumbnail',
        'library'       => 'all',
        'min_width'     => 0,
        'min_height'    => 0,
        'max_width'     => 0,
        'max_height'    => 0,
    ) );
    // Office
    acf_add_local_field( array(
        'key'          => 'field_office',
        'label'        => 'Office',
        'name'         => 'office',
        'type'         => 'text',
        'parent'       => 'group_person_details',
        'instructions' => '',
        'required'     => 0,
    ) );
    // E-mail
    acf_add_local_field( array(
        'key'          => 'field_email',
        'label'        => 'E-mail',
        'name'         => 'email',
        'type'         => 'email',
        'parent'       => 'group_person_details',
        'instructions' => '',
        'required'     => 0,
    ) );
    // Office Phone
    acf_add_local_field( array(
        'key'          => 'field_phone',
        'label'        => 'Phone',
        'name'         => 'phone',
        'type'         => 'text',
        'parent'       => 'group_person_details',
        'instructions' => '',
        'required'     => 0,
    ) );
    // Affiliation
    acf_add_local_field( array(
        'key'             => 'field_affiliation',
        'label'           => 'Affiliation',
        'name'            => 'affiliation',
        'type'            => 'taxonomy',
        'parent'          => 'group_person_details',
        'instructions'    => '',
        'required'        => 0,
        'taxonomy'        => 'affiliation',
        'field_type'      => 'multi_select',      // UI (checkbox, multi-select, select, radio)
        'allow_null'      => 0,             // Can select a blank value
        'load_save_terms' => 1,             // Persist using term relationships table
        'return_format'   => 'object',      // or 'object'
        'add_term'        => 0,             // Can the user add new terms?
    ) );
}
}
add_action( 'init', 'register_custom_acf_fields' );

0 个答案:

没有答案