为了做到这一点,我必须隐藏默认ACF输出中的字段。在核心中无法做到这一点,下划线可以在其他任何地方禁用输出,但编辑区域是一个例外。
我使用以下代码创建了一个隐藏字段类型,它不输出任何输入,并且隐藏自己的标签。它基于https://github.com/gerbenvandijk/acf-hidden-field
<?php
class acf_field_hidden_field extends acf_field
{
// vars
var $settings, // will hold info such as dir / path
$defaults; // will hold default field options
/*
* __construct
*
* Set name / label needed for actions / filters
*
* @since 3.6
* @date 23/01/13
*/
function __construct()
{
// vars
$this->name = \'hidden_field\';
$this->label = __(\'Hidden field\');
$this->category = __("Basic",\'acf\'); // Basic, Content, Choice, etc
$this->defaults = array(
// add default here to merge into your field.
// This makes life easy when creating the field options as you don\'t need to use any if( isset(\'\') ) logic. eg:
//\'preview_size\' => \'thumbnail\'
);
// do not delete!
parent::__construct();
// settings
$this->settings = array(
\'path\' => apply_filters(\'acf/helpers/get_path\', __FILE__),
\'dir\' => apply_filters(\'acf/helpers/get_dir\', __FILE__),
\'version\' => \'1.0.0\'
);
}
/*
* create_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field\'s data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field )
{
// defaults?
/*
$field = array_merge($this->defaults, $field);
*/
// perhaps use $field[\'preview_size\'] to alter the markup?
// create Field HTML
?>
<style>div[data-key="<?php echo $field[\'key\'];?>"]{ display: none;}</style>
<?php
}
}
// create field
new acf_field_hidden_field();
?>
我还使用自己的自定义元框以我的方式将数据引入。我对字段进行了“标记”,将它们命名为技术上隐藏的字段(如
hide_title
和
hide_desc
). 通过使用自定义屏幕,它不会影响常规的前端显示。