Php 如何创建只读afc字段
Php 如何创建只读afc字段,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我是PHP和wordpress的新手 我创建了自定义字段“Field1” 我只想在创建帖子时编辑此字段 我该怎么做呢?也许不是最优雅的方式,但嘿,它很管用 /** * Prevents a field from being updated from the panel in ACF. * Useful for business-critical fields that must only be updated internally, but still need to be visi
我是PHP和wordpress的新手
我创建了自定义字段“Field1”
我只想在创建帖子时编辑此字段
我该怎么做呢?也许不是最优雅的方式,但嘿,它很管用
/**
* Prevents a field from being updated from the panel in ACF.
* Useful for business-critical fields that must only be updated internally, but still need to be visible on the admin panel.
*/
add_filter('acf/update_value/key=YOUR_FIELD_KEY/NAME', function($value, $post_id, $field) {
$backtraces = debug_backtrace();
foreach ($backtraces as $backtrace) {
if ( ! empty($backtrace['function']) && $backtrace['function'] == 'update_field') {
return $value;
}
}
return get_field('YOUR_FIELD_KEY/NAME', $post_id, false);
}, 10, 3);
在位置中放置
帖子类型等于帖子
我这样做了,没有帮助当你说“仅当我创建帖子时”时,你到底是什么意思?我不想有可能更新此字段而不是等于更改为不等于