I have following json
{
"status": "ok",
"totalResults": 2,
"articles": [
{
"source": {
"id": "cooking-recepie",
"name": "cooking recepie"
},
"author": "cooking recepie Staff",
"title": "lamb steak",
"description": "fffffffffffffffffffffff.”",
"url": "http://www.cooking-recepie.net/node/116605",
"urlToImage": "https://www.cooking-
recepie.net/sites/default/[type]/[nid]/conte-1801-cap-epa.jpg",
"publishedAt": "2018-02-02T01:00:00Z"
},
{
"source": {
"id": "cooking-recepie",
"name": "cooking recepie"
},
"author": "cooking recepie Staff",
"title": "Igghhhhhhhhhhhhhhhhhhhh?",
"description": "yhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.",
"url": "http://www.cooking-recepie.net/116598/inter-push-lautaro-
martinez",
"urlToImage": "https://www.cooking-recepie.net/sites/[nid]/Martinez-
Lautaro-Arg-epa_0_0.jpg",
"publishedAt": "2018-02-02T01:00:00Z"
}
]
}
—————————–so far my code to test——-
<?php
$request = wp_remote_get( 'https://url' );
if( is_wp_error( $request ) ) {
return false;
}
$body = wp_remote_retrieve_body( $request );
$data = json_decode( $body );
if( ! empty( $data ) ) {
if (is_array($data) || is_object($data))
{
foreach ($data as $key => $val){
echo 'data:'.$data->$key->$val.'<br>';
echo 'key:'.$key.'<br>';
echo 'val:'. $val.'<br>';
}
}
}
?>
————————-response———–
data:
key:status
val:ok
data:
key:totalResults
val:2
data:
key:articles
val:Array
—————————–my questions ———————-
- is it object or array?, i am displaying in a php widget, but it keeps
on getting error. - i need to display all info
- is it safe using wp-remote-get in php widget displaying live?
- how to cache the results?