I am looking at how to condense this down into a proper "for loop" which means it runs the text, value, and id fields for the length of the json array.
This works but is not dynamic. there has to be a way to do this and I just cant find an example how beyond the point I'm at.
array(
"text" => $data[3]['name'],
"value" => $data[3]['slug'],
"id" => "id-2"
)
Everything I have found so far has been useful but nothing past this point and I'm sure it's a simple answer.
what this does is get all the entries within a taxonomy to populate a drop-down form's field
function myfunction() {
$request = wp_remote_get( 'https://shatner/wp-json/wpas-api/v1/enterprize-crew?type=name' );
if( is_wp_error( $request ) ) {
return false; // Bail early
}
$body = wp_remote_retrieve_body( $request );
$data = json_decode( $body, true );
$elementCount = count($data);
foreach($data as $key['name'] => $value) {
$options = array(
array(
"text" => $data[0]['name'],
"value" => $data[0]['slug'],
"id" => "id-1"
),
array(
"text" => $data[1]['name'],
"value" => $data[1]['slug'],
"id" => "id-2"
),
array(
"text" => $data[2]['name'],
"value" => $data[2]['slug'],
"id" => "id-1"
),
array(
"text" => $data[3]['name'],
"value" => $data[3]['slug'],
"id" => "id-2"
)
);
return $options;
}
}
id-1, id-2, id-1, id-2orid-1, id-2, id-3, id-4?