You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Metabox关联到指定页面(以about-us页面为例)

解决方法

要让ACF字段组仅显示在slug为about-us的页面,只需修改字段组配置中的location数组:

  • 将param的值从page_type改为page
  • 将value的值从front_page改为目标页面的slug(about-us)或页面ID

修改后的完整代码如下:

<?php
acf_add_local_field_group(array (
    'key' => 'group_1',
    'title' => 'My Group',
    'fields' => array (
        array (
            'key' => 'field_1',
            'label' => 'Sub Title',
            'name' => 'sub_title',
            'type' => 'text',
            'prefix' => '',
            'instructions' => '',
            'required' => 0,
            'conditional_logic' => 0,
            'wrapper' => array (
                'width' => '',
                'class' => '',
                'id' => '',
            ),
            'default_value' => '',
            'placeholder' => '',
            'prepend' => '',
            'append' => '',
            'maxlength' => '',
            'readonly' => 0,
            'disabled' => 0,
        )
    ),
    'location' => array (
        array (
            array (
                'param' => 'page',
                'operator' => '==',
                'value' => 'about-us',
            ),
        ),
    ),
    'menu_order' => 0,
    'position' => 'normal',
    'style' => 'default',
    'label_placement' => 'top',
    'instruction_placement' => 'label',
    'hide_on_screen' => '',
));

补充说明

  • 如果更倾向于使用页面ID而非slug,直接将value替换为对应页面的数字ID即可(例如'value' => 123)
  • 若需要同时匹配多个条件(比如既指定页面类型又指定具体页面),可以在内部数组中添加更多条件规则

内容的提问来源于stack exchange,提问作者Сергей

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 09:40:57