1

我正在尝试在我的 functions.php 文件中包含一些我创建的自定义字段,因此它们是我正在处理的主题的原生字段。但是,它们没有出现在我设置的帖子的编辑屏幕上。

通过在我的functions.php中使用此代码,我已将acf插件包含在我的主题中: include_once('advanced-custom-fields/acf.php');

我还将字段导出到 php,并将代码复制并粘贴到我的主题的 functions.php 中。谁能告诉我我做错了什么?

下面是我导出的代码

define( 'ACF_LITE', true );

include_once('/advanced-custom-fields/acf.php');

如果(函数存在('register_field_group')):

register_field_group(array (
    'id' => 'acf_about-us',
    'title' => 'About Us',
    'fields' => array (
        array (
            'key' => 'field_586e22820cdf9',
            'label' => 'About Us',
            'name' => 'about_us',
            'type' => 'text',
            'instructions' => 'Enter Title for about us here',
            'required' => 1,
            'default_value' => '',
            'placeholder' => 'Enter Title for about us here',
            'prepend' => '',
            'append' => '',
            'formatting' => 'none',
            'maxlength' => '',
        ),
        array (
            'key' => 'field_586e22f80cdfa',
            'label' => 'Establised At',
            'name' => 'establised_at',
            'type' => 'text',
            'required' => 1,
            'default_value' => '',
            'placeholder' => 'When where you established',
            'prepend' => '',
            'append' => '',
            'formatting' => 'none',
            'maxlength' => '',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'page',
                'operator' => '==',
                'value' => '15',
                'order_no' => 0,
                'group_no' => 0,
            ),
        ),
    ),
    'options' => array (
        'position' => 'normal',
        'layout' => 'default',
        'hide_on_screen' => array (
        ),
    ),
    'menu_order' => 0,
));
register_field_group(array (
    'id' => 'acf_food-menu',
    'title' => 'Food Menu',
    'fields' => array (
        array (
            'key' => 'field_58808cfded5b3',
            'label' => 'Price',
            'name' => 'price',
            'type' => 'text',
            'required' => 1,
            'default_value' => '',
            'placeholder' => '',
            'prepend' => '',
            'append' => '',
            'formatting' => 'html',
            'maxlength' => '',
        ),
        array (
            'key' => 'field_5881f02f46739',
            'label' => 'Currency',
            'name' => 'currency',
            'type' => 'select',
            'required' => 1,
            'choices' => array (
                '$' => '$',
                '&euro' => '€',
            ),
            'default_value' => '',
            'allow_null' => 0,
            'multiple' => 0,
        ),
        array (
            'key' => 'field_5880aceb6427c',
            'label' => 'Food Category',
            'name' => 'food_category',
            'type' => 'checkbox',
            'required' => 1,
            'choices' => array (
                'breakfast' => 'Breakfast',
                'lunch' => 'Lunch',
                'dinner' => 'Dinner',
                'party' => 'Party',
                'drinks' => 'Drinks',
            ),
            'default_value' => 'breakfast : Breakfast',
            'layout' => 'vertical',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'post_type',
                'operator' => '==',
                'value' => 'foodmenu',
                'order_no' => 0,
                'group_no' => 0,
            ),
        ),
    ),
    'options' => array (
        'position' => 'normal',
        'layout' => 'no_box',
        'hide_on_screen' => array (
        ),
    ),
    'menu_order' => 0,
));
register_field_group(array (
    'id' => 'acf_footer-details',
    'title' => 'Footer details',
    'fields' => array (
        array (
            'key' => 'field_5878f731da3ad',
            'label' => 'footer image',
            'name' => 'footer_image',
            'type' => 'image',
            'instructions' => 'Footer Image Goes Here',
            'save_format' => 'object',
            'preview_size' => 'medium',
            'library' => 'all',
        ),
        array (
            'key' => 'field_5878f756da3ae',
            'label' => 'footer content',
            'name' => 'footer_content',
            'type' => 'text',
            'instructions' => 'footer content goes here',
            'default_value' => '',
            'placeholder' => '',
            'prepend' => '',
            'append' => '',
            'formatting' => 'none',
            'maxlength' => '',
        ),
        array (
            'key' => 'field_58794f98697fa',
            'label' => 'Social Icons',
            'name' => '',
            'type' => 'tab',
        ),
        array (
            'key' => 'field_58794d05697f8',
            'label' => 'Facebook Username',
            'name' => 'facebook_username',
            'type' => 'text',
            'instructions' => 'Enter Your Facebook Username Here',
            'default_value' => '',
            'placeholder' => 'ajbeacon',
            'prepend' => '',
            'append' => '',
            'formatting' => 'none',
            'maxlength' => '',
        ),
        array (
            'key' => 'field_58794c93697f7',
            'label' => 'Twitter Username',
            'name' => 'twitter_username',
            'type' => 'text',
            'instructions' => 'Enter Twitter Username Here',
            'default_value' => '',
            'placeholder' => 'ajbeacon',
            'prepend' => '@',
            'append' => '',
            'formatting' => 'none',
            'maxlength' => '',
        ),
        array (
            'key' => 'field_58794d65697f9',
            'label' => 'Google Plus Username',
            'name' => 'google_plus_username',
            'type' => 'text',
            'instructions' => 'Enter Your Google Plus Username Here',
            'default_value' => '',
            'placeholder' => '+ajbeacon',
            'prepend' => '',
            'append' => '',
            'formatting' => 'none',
            'maxlength' => '',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'page',
                'operator' => '==',
                'value' => '15',
                'order_no' => 0,
                'group_no' => 0,
            ),
        ),
    ),
    'options' => array (
        'position' => 'normal',
        'layout' => 'default',
        'hide_on_screen' => array (
        ),
    ),
    'menu_order' => 0,
));
register_field_group(array (
    'id' => 'acf_opening-time',
    'title' => 'Opening Time',
    'fields' => array (
        array (
            'key' => 'field_58795883ae60c',
            'label' => 'Opening Time',
            'name' => '',
            'type' => 'tab',
        ),
        array (
            'key' => 'field_587957a30aecf',
            'label' => 'Breakfast',
            'name' => 'breakfast',
            'type' => 'wysiwyg',
            'required' => 1,
            'default_value' => '',
            'toolbar' => 'full',
            'media_upload' => 'yes',
        ),
        array (
            'key' => 'field_587957f00aed0',
            'label' => 'Lunch',
            'name' => 'lunch',
            'type' => 'wysiwyg',
            'required' => 1,
            'default_value' => '',
            'toolbar' => 'full',
            'media_upload' => 'yes',
        ),
        array (
            'key' => 'field_587958310aed1',
            'label' => 'Dinner',
            'name' => 'dinner',
            'type' => 'wysiwyg',
            'required' => 1,
            'default_value' => '',
            'toolbar' => 'full',
            'media_upload' => 'yes',
        ),
        array (
            'key' => 'field_58795c760f586',
            'label' => 'Direction',
            'name' => '',
            'type' => 'tab',
        ),
        array (
            'key' => 'field_58795c900f587',
            'label' => 'Address',
            'name' => 'address',
            'type' => 'text',
            'default_value' => '',
            'placeholder' => 'Enter Address Here',
            'prepend' => '',
            'append' => '',
            'formatting' => 'none',
            'maxlength' => '',
        ),
        array (
            'key' => 'field_58795d8550af4',
            'label' => 'Contact Details',
            'name' => '',
            'type' => 'tab',
        ),
        array (
            'key' => 'field_58795da950af5',
            'label' => 'Email',
            'name' => 'email',
            'type' => 'email',
            'required' => 1,
            'default_value' => '',
            'placeholder' => 'Enter contact Email Address here',
            'prepend' => '',
            'append' => '',
        ),
        array (
            'key' => 'field_58795dde50af6',
            'label' => 'Phone Number',
            'name' => 'phone_number',
            'type' => 'text',
            'required' => 1,
            'default_value' => '',
            'placeholder' => 'Enter Reachable Contact Phone Number Here.',
            'prepend' => '',
            'append' => '',
            'formatting' => 'html',
            'maxlength' => '',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'page',
                'operator' => '==',
                'value' => '15',
                'order_no' => 0,
                'group_no' => 0,
            ),
        ),
    ),
    'options' => array (
        'position' => 'normal',
        'layout' => 'default',
        'hide_on_screen' => array (
        ),
    ),
    'menu_order' => 0,
));
register_field_group(array (
    'id' => 'acf_signature-dishes',
    'title' => 'Signature Dishes',
    'fields' => array (
        array (
            'key' => 'field_5878ff13d8ea4',
            'label' => 'Signature Dishes',
            'name' => 'signature_dishes',
            'type' => 'text',
            'required' => 1,
            'default_value' => '',
            'placeholder' => 'Enter Title Here Please',
            'prepend' => '',
            'append' => '',
            'formatting' => 'none',
            'maxlength' => '',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'page',
                'operator' => '==',
                'value' => '15',
                'order_no' => 0,
                'group_no' => 0,
            ),
        ),
    ),
    'options' => array (
        'position' => 'normal',
        'layout' => 'no_box',
        'hide_on_screen' => array (
        ),
    ),
    'menu_order' => 0,
));

万一;

4

1 回答 1

0

感谢您发布帮助很大的代码。

代码是正确的,唯一可能的错误是包含 acf.php

如果您可以访问 FTP,请将“advanced-custom-fields”文件夹放在 functions.php 文件旁边。(在同一目录中)

现在在functions.php(您在上面发布的代码)中找到这一行:

include_once('/advanced-custom-fields/acf.php');

用这个替换它:

 include_once('advanced-custom-fields/acf.php');

如果这不起作用,请告诉我。

谢谢

于 2017-01-23T06:35:46.683 回答