两种帖子类型的高级自定义字段 - wordpress

时间:2016-03-21 14:16:57

标签: php wordpress advanced-custom-fields

我需要在两个页面中添加带有php的字段(在 高级自定义字段插件 wordpress

这是我的尝试:

acf_add_local_field_group(array (
    'key' => 'songs_options',
    'title'      => 'songs options',
    'fields' => array (
        array (
            'key' => 'field_1',
            'label' => 'test title',
            'name' => 'test_field',
            'type' => 'text',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'post_type',
                'operator' => 'IN', 
                'value' => array( 'songs', 'videos'),  // i need a code like this line
            ),
        )
    ),
));

1 个答案:

答案 0 :(得分:1)

您应该将'=='运算符与位置一起使用,并将每个位置添加为“位置”下的不同数组:

register_field_group(array (
    'key' => 'songs_options',
    'title'      => 'songs options',
    'fields' => array (
        array (
            'key' => 'field_1',
            'label' => 'test title',
            'name' => 'test_field',
            'type' => 'text',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'post_type',
                'operator' => '==', 
                'value' => 'songs',
            ),
        ),
        array (
            array (
                'param' => 'post_type',
                'operator' => '==', 
                'value' => 'videos',
            ),
        ),
    ),
));