答案 0 :(得分:0)
我把这个函数放到了我的function.php中,所以我只需要在custum表中添加我的选项,例如像国家一样。
function makeChoiceArrayForACF($postid){
$datafromdbase = someFunctionToGetDataFromDbase();
$newdbasearray = array();
foreach ($datafromdbase as $key => $value){
$newdbasearray[$key] = $key;
}
$new = array(
'multiple' => 0,
'allow_null' => 1,
'choices' =>
$newdbasearray,
'default_value' =>
array(),
'ui' => 0,
'ajax' => 0,
'placeholder' => '',
'return_format' => 'array',
'type' => 'select',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' =>
array(
'width' => '',
'class' => '',
'id' => '',
),
);
$my_post = array(
'ID' => $postid,
'post_content' => serialize($new),
);
wp_update_post( $my_post );
}
add_action('init', 'admin_only');
function admin_only() {
if( !is_admin() )
return;
makeChoiceArrayForACF(16611);
}