I've made this function to get the post id from WP Api , and Render it from server ( not by Js or Ajax ).
function api_featured_item_id($url) {
$data = file_get_contents($url); // put the contents of the file into a variable
$posts = json_decode($data,true); // decode the JSON feed
$i = 0;
$outuput = '';
foreach( $posts as $item ) {
$outuput .= $item['id'] .',';
$i++;
if($i==4) break;
}
return $outuput;
}
In local it work, after moving online, i've this error :
Warning: file_get_contents(): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in /home/public_html/website/wp-content/mu-plugins/general-functions.php
If I try to open the url on browser, work fine and I can see the Json Data correctly. I've set via PHP Ini the allow_url_fopen "enabled" , but not work.