How to load Post Type fields with data from a remote API
-
I need to bring the information of a Post Type from a Remote URL that show a json file.
This information will be loaded into WP-Admin to allow user selection when Filling in custom fields on a page.
Sample of remote url(json)
{ "id": 1, "nome": "Tribunal de Justi?a do Estado do Acre", "sigla": "TJAC", "unidades": [{ "id": 2, "nome": "Acrelandia", "sigla": "AL", "unidades": [{ "id": 24, "nome": "Dire??o do Foro", "sigla": "ALDFO", "unidades": [ ], "tipo": "ADMINISTRATIVA" }, { "id": 25, "nome": "Vara única", "sigla": "ALVAR", "unidades": [ ], "tipo": "VARA" } ], "tipo": "COMARCA" }, { "id": 3, "nome": "Assis Brasil", "sigla": "AB", "unidades": [{ "id": 26, "nome": "Dire??o do Foro", "sigla": "ABDFO", "unidades": [ ], "tipo": "ADMINISTRATIVA" }, { "id": 27, "nome": "Vara única", "sigla": "ABVAR", "unidades": [ ], "tipo": "VARA" } ], "tipo": "COMARCA" } }
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;
I need to load the api data into the ACF fields, to allow editing the Page Fields in WP Admin.
How do I implement this?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to load Post Type fields with data from a remote API’ is closed to new replies.