首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从php文件中获取acf字段

从php文件中获取acf字段
EN

Stack Overflow用户
提问于 2016-05-06 00:12:11
回答 1查看 672关注 0票数 0

我将此代码放入我的functions.php中

代码语言:javascript
复制
include_once('advanced-custom-fields/acf.php');
include_once('acf-options-page/acf-options-page.php');
include_once('acf-repeater/acf-repeater.php');
define( 'ACF_LITE', true );

if(function_exists("register_field_group"))
{

    register_field_group(array (
        'id' => 'acf_options',
        'title' => 'Options',
        'fields' => array (
            array (
                'key' => 'field_525d1b6d49043',
                'label' => 'lable',
                'name' => 'homepage',
                'type' => 'repeater',
                'instructions' => 'Select which categories you want to display on the homepage.',
                'sub_fields' => array (
                    array (
                        'key' => 'field_525d1b8a49044',
                        'label' => 'Category',
                        'name' => 'firsttext',
                        'type' => 'text',
                        'column_width' => '',
                        'field_type' => 'text',
                        'return_format' => 'id',
                    ),
                    array (
                        'key' => 'field_525d2473de72c',
                        'label' => 'Number of Posts',
                        'name' => 'number-of-posts',
                        'type' => 'text',
                        'column_width' => '',
                        'default_value' => 4,
                        'placeholder' => '',
                        'prepend' => '',
                        'append' => '',
                        'min' => 2,
                        'max' => '',
                        'step' => 2,
                    ),
                ),
                'row_min' => 1,
                'row_limit' => 1,
                'layout' => 'row',
                'button_label' => 'Add a category',
            ),


        ),
        'location' => array (
            array (
                array (
                    'param' => 'options_page',
                    'operator' => '==',
                    'value' => 'acf-options',
                    'order_no' => 0,
                    'group_no' => 0,
                ),
            ),
        ),
        'options' => array (
            'position' => 'normal',
            'layout' => 'no_box',
            'hide_on_screen' => array (
            ),
        ),
        'menu_order' => 0,
    ));
}

然后,我在管理控制台的字段中输入值

如何从页面文件中获取此值?

我尝试了get_field('acf_options)和get_field('homepage),但这返回null

EN

回答 1

Stack Overflow用户

发布于 2016-05-06 00:30:42

我不知道为什么你想把它放到你的function.php文件中,而不是通过插件来做。

但是,如果您想检索这些字段值,您应该这样做:get_field( 'homepage', 'option' );而不是:get_field( 'homepage' )get_field( 'acf_options' )

我最好的建议是在ACF website上查找信息。这些文档帮助很大!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37055335

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档