0

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.

The 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
 }
}

MY FUNCTION FILE

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;
}

Here is the output form

$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>';

FRONT-END OUTPUT

Screenshot from 2017-01-20 19:21:17.png

QUESTION

How can I output the JSON file countries in the dropdown

0

Edit output form with $form .= '<option value="" >' . $data['name'] . '</option>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.