如何用来自远程API的数据加载Post Type字段



我需要从显示json文件的远程URL带来Post类型的信息。

我的数据是:

Comarca > Unidade > Setor

我需要tó加载数据从json URL在后端选择

远程url(json)示例

{
"id": 1,
"nome": "Tribunal de Justiça do Estado do Acre",
"sigla": "TJAC",
"comarcas": [{
"id": 2,
"nome": "Acrelândia",
"sigla": "AL",
"unidades": [{
"id": 24,
"nome": "Direção do Foro",
"sigla": "ALDFO",
"setor": [{
"id": 28,
"nome": "Vara Cível",
"sigla": "ACVCI",
"tipo": "VARA"
},
{
"id": 30,
"nome": "Vara Criminal",
"sigla": "ACVCR",
"tipo": "VIRTUAL"
}
],
"tipo": "ADMINISTRATIVA",
]
}
[{
"id": 2,
"nome": "Rio Branco",
"sigla": "RB",
"unidades": [{
"id": 24,
"nome": "Direção do Foro",
"sigla": "ALDFO",
"setor": [{
"id": 28,
"nome": "Central de Execução de Penas e Medidas Alternativas",
"sigla": "BRCEPAL",
"tipo": "VARA"
},
{
"id": 30,
"nome": "Juizado Especial Criminal",
"sigla": "BRJECRIM",
"tipo": "VIRTUAL"
}
],
"tipo": "ADMINISTRATIVA"
}]
}]
}
}

此信息将被加载到WP-Admin中,以便在页面上填写自定义字段时允许用户选择。

字段"Comarca"=比;收到(comarca)

字段"Unidade"=比;收到(unidade)

字段"sertor"=比;动态选择[comarca]和[unidade]后接收[name]

字段" sigla " =>收到(sigla)

字段"Tipo"=比;收到(蒂波)

My Custom Fields Created in ACF
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_6100ec8d1bf79',
'title' => 'Lotação',
'fields' => array(
array(
'key' => 'field_6100f04affa8f',
'label' => 'Nome',
'name' => 'nome',
'type' => 'text',
'instructions' => 'Nome da Unidade',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => 'Nome da Unidade',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_6100f3c5ffa91',
'label' => 'Sigla',
'name' => 'sigla',
'type' => 'text',
'instructions' => 'Informar a Sigla da Unidade',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => 6,
),
array(
'key' => 'field_6100f076ffa90',
'label' => 'Comarca',
'name' => 'comarca',
'type' => 'taxonomy',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'taxonomy' => 'comarca',
'field_type' => 'checkbox',
'add_term' => 0,
'save_terms' => 0,
'load_terms' => 0,
'return_format' => 'id',
'multiple' => 0,
'allow_null' => 0,
),
array(
'key' => 'field_6100f421ffa92',
'label' => 'Tipo',
'name' => 'tipo',
'type' => 'select',
'instructions' => 'Selecionar Administrativo | Primeiro Grau | Segundo Grau',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'ad' => 'Administrativo',
'pg' => 'Primeiro Grau',
'sg' => 'Segundo Grau',
),
'default_value' => 'ad',
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
'return_format' => 'array',
'ajax' => 0,
'placeholder' => '',
),
array(
'key' => 'field_61035043400f1',
'label' => 'Id Parent',
'name' => 'id_parent',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'lotacao',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;

我正在研究使这成为可能的实现模型。

我认为你可以使用XMLHttpRequest作为POST传递JSON数据。

最新更新