无法在acf / init

时间:2018-10-28 13:13:22

标签: wordpress custom-post-type

正在尝试在我的函数中获取单个产品页面的ID,但它返回的是 bool(false) NULL

试图达到的目的是获得ID来过滤特定产品的类别分类术语,并使用ACF将其显示在选项卡中,但是不幸的是无法获得ID。

我在为单个产品编辑页面添加的元框中使用了global $post代码,所以我不确定这里缺少什么。

下面是我的代码:

function my_acf_add_local_field_groups() {

    global $post;

    var_dump($post); // returns NULL and bool(false) when echo'd

    acf_add_local_field_group(array(
    'key' => 'tab_group_1',
    'title' => 'Product Sizes and Prices',
    'name' => 'group_sizes_tab',
    'fields' => array (
        array (
            'key'               => 'field_tab_size_1',
            'label'             => 'First Size',
            'name'              => 'store_sizes_',
            'type'              => 'tab',
            'parent'            => 'tab_group_1',
            'instructions'      => '',
            'required'          => 0,
            'conditional_logic' => 0,
            'wrapper'           => array (
                'width'             => '',
                'class'             => '',
                'id'                => '',
            ),
            'collapsed'         => '',
            'min'               => '',
            'max'               => '',
        ),
        array (
            'key' => 'field_unique_key',
            'label' => 'Simple Repeater',
            'name' => 'simple_repeater',
            'type' => 'repeater',
            'instructions' => '',
            'required' => 0,
            'conditional_logic' => 0,
            'wrapper' => array (
                'width' => '',
                'class' => '',
                'id' => '',
            ),
            'collapsed' => '',
            'min' => 0,
            'max' => 10,
            'layout' => 'table',
            'button_label' => 'Add row',
            'sub_fields' => array ( 
                array (
                    'key' => 'field_unique_key_1',
                    'label' => 'Total Products',
                    'name' => 'total_products',
                    'type' => 'text',
                ),
                array (
                    'key' => 'field_unique_key_2',
                    'label' => 'Total Prices',
                    'name' => 'total_prices',
                    'type' => 'text',
                ),
            ),

        ),
        array (
            'key'               => 'field_tab_size_2',
            'label'             => 'Second Size',
            'name'              => 'store_sizes_2',
            'type'              => 'tab',
            'parent'            => 'tab_group_1',
            'instructions'      => '',
            'required'          => 0,
            'conditional_logic' => 0,
            'wrapper'           => array (
                'width'             => '',
                'class'             => '',
                'id'                => '',
            ),
            'collapsed'         => '',
            'min'               => '',
            'max'               => '',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'post_type',
                'operator' => '==',
                'value' => 'products',
            ),
        ),
    ),
));

 }

 add_action('acf/init', 'my_acf_add_local_field_groups');

0 个答案:

没有答案