How to access CryptoWP data in custom templates

The real power of CryptoWP comes when working in custom templates. With access to raw coin data, you can create just about anything, including price calculators, and custom price tickers.

CryptoWP stores all coin data in a single option in the WordPress Options table. In your theme or plugin, you can refer to the handy get_cryptowp() function to display a list of your coin data in templates:

Note: as of version 1.3 the data format has slightly changed and cryptowp_data() is now deprecated in favor of get_cryptowp() (see below).

<?php get_cryptowp( $field = null, $key = null, $atts = null  ); ?>

Example output:

Array (
	[currency] =>
	[currency_sign] =>
	[coins] => Array (
		[BTC] => Array (
			[name] => Bitcoin
			[icon] => https://domain.com/wp-content/uploads/2017/09/bitcoin.png
			[id] => bitcoin
			[symbol] => BTC
			[percent] => -5.49
			[price] => 12,937.30
			[value] => decrease
			[price_btc] => 1.0
			[supply] => 16773187.0
			[market_cap] => 216999752175
			[error] =>
			[sign] =>
			[percent_change_1h] => -2.85
			[percent_change_24h] => -5.49
		)
		[ETH] => Array (
			[name] => Ethereum
			[icon] => https://domain.com/wp-content/uploads/2017/08/ethereum.png
			[id] => ethereum
			[symbol] => ETH
			[percent] => 0.45
			[price] => 715.74
			[value] => increase
			[price_btc] => 0.0556923
			[supply] => 96677516.0
			[market_cap] => 69196255535.0
			[error] =>
			[sign] =>
			[percent_change_1h] => -1.49
			[percent_change_24h] => 0.45
		)
		[...]
	)
)

Calling this function will access all CryptoWP settings data, and the available parameters allow you to quickly traverse the options array to get the data you need.

To access all coins data only, fill in the $field parameter:

get_cryptowp( 'coins' );

To access all data about a specific coin, go deeper using the $key parameter to search for coins by ticker symbol:

get_cryptowp( 'coins', 'BTC' );

Finally, access a specific coin attribute with the $atts parameter:

get_cryptowp( 'coins', 'BTC', 'price' );