【问题标题】:Advanced custom fields on two post type - wordpress两种帖子类型的高级自定义字段 - wordpress
【发布时间】:2016-03-21 23:28:38
【问题描述】:

我需要在两个页面中使用 php 添加字段(在 advanced custom fields plugin ,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
            ),
        )
    ),
));

【问题讨论】:

    标签: php wordpress advanced-custom-fields


    【解决方案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',
                ),
            ),
        ),
    ));
    

    【讨论】:

    • 谢谢,我把“IN”改成了“==”,两个帖子类型加了框
    • 但我不能(发布/更新)发布(在后期编辑 wp-admin 中)!当我使用这个功能时
    • 对不起,我忘记更改复制粘贴中的“IN”! :P 现在已编辑
    • 当您点击发布/更新时,wordpress 是否打印任何错误?
    • 点击后控制台提示:TypeError: invalid 'in' operand a - jquery.js -localhost/wordpress/wp-includes/js/jquery/jquery.js?ver=1.11.3
    猜你喜欢
    • 2018-01-29
    • 1970-01-01
    • 2016-07-19
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 2021-04-30
    相关资源
    最近更新 更多