Shortcode_get_api_demo
// Add Shortcode
function recent_posts_api_shortcode( $atts , $content = null ) {
// Attributes
$atts = shortcode_atts(
array(
'posts' => '5',
),
$atts,
'recent-posts-api'
);
$convert_to = 'MXN';
$just_show = 5;
$api_url = 'https://api.coinmarketcap.com/v1/?convert=' . $convert_to . '&limit=' . $just_show;
$response = wp_remote_get( $api_url );
$array_api = json_decode( wp_remote_retrieve_body( $response ), true );
//var_dump($cryptocurrencies[0]["id"]);
$output = '<ul>';
foreach ( $array_api as $key => $data ) {
$output .= '<li>';
$output .= 'Id ' . $array_api[$key]["id"] .'</li>';
$output .= 'price' . $array_api[$key]["price_usd"];
$output .= '</li>';
}
$output .= '<ul>';
}
add_shortcode( 'recent-posts-api', 'recent_posts_api_shortcode' );