I am having a problem with populating a select dropdown from a JSON
file.
I am modifying an existing plugin, and I want to include countries that we want to see to.
JSON
FILE{
"AX": {
"name": "Åland Islands",
"lpa": "18",
"affirm_non_muslim": false
},
"AF": {
"name": "Afghanistan",
"lpa": "0",
"affirm_non_muslim": false
},
"AL": {
"name": "Albania",
"lpa": "18",
"affirm_non_muslim": false
},
"DZ": {
"name": "Algeria",
"lpa": "18",
"affirm_non_muslim": false
}
}
function av_get_json_data(){
$json_url = require( plugin_dir_path( __FILE__ ) . '../includes/data/country_age.json' );
$args = array('timeout' => 120);
$json_feed = wp_remote_get( $json_url, $args );
$json_string_in_array = array('$json_feed');
$json_array = json_decode($json_string_in_array[0]);
//$actual_feed = json_decode($json_array);
return $json_array;
}
$form .= '</select> <select name="av_verify_l" id="av_verify_l">';
foreach (av_get_json_data() as $data) :
$form .= '<option value="" >' . $data . '</option>';
endforeach;
$form .='<select>';
How can I output the JSON file countries in the dropdown
I am having a problem with populating a select dropdown from a JSON
file.
I am modifying an existing plugin, and I want to include countries that we want to see to.
JSON
FILE{
"AX": {
"name": "Åland Islands",
"lpa": "18",
"affirm_non_muslim": false
},
"AF": {
"name": "Afghanistan",
"lpa": "0",
"affirm_non_muslim": false
},
"AL": {
"name": "Albania",
"lpa": "18",
"affirm_non_muslim": false
},
"DZ": {
"name": "Algeria",
"lpa": "18",
"affirm_non_muslim": false
}
}
function av_get_json_data(){
$json_url = require( plugin_dir_path( __FILE__ ) . '../includes/data/country_age.json' );
$args = array('timeout' => 120);
$json_feed = wp_remote_get( $json_url, $args );
$json_string_in_array = array('$json_feed');
$json_array = json_decode($json_string_in_array[0]);
//$actual_feed = json_decode($json_array);
return $json_array;
}
$form .= '</select> <select name="av_verify_l" id="av_verify_l">';
foreach (av_get_json_data() as $data) :
$form .= '<option value="" >' . $data . '</option>';
endforeach;
$form .='<select>';
How can I output the JSON file countries in the dropdown
Edit output form with
$form .= '<option value="" >' . $data['name'] . '</option>';