我是PHP和wordpress的新人
我创建了自定义字段" Field1"
我希望只有在创建帖子时才有可能编辑此文件
我该怎么做?
答案 0 :(得分:1)
也许不是最优雅的方式,但是,嘿,行得通!
/**
* 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);