1
我試圖從這個json文件中獲取數據,但我需要匹配高級自定義字段的數據。WooCommerce:獲取多維數組中匹配ACF自定義字段的Json數據
$str = file_get_contents('http://gold.explorethatstore.com/wp-content/themes/divi-ETS-child-theme/run_results_bgasc.json');
// decode JSON
$json = json_decode($str, true);
// default value
$coinPrice = "Not Available";
$vendorName = get_field('bgasc_vendor_name');
// loop the json array
foreach($json['coin'] as $value){
// check the condition
if($value['coin_name'] == $vendorName){
$coinPrice = $value['url']; // get the price
break; // exit the loop
}
}
echo $coinPrice;
有一個問題,有些時候,例如類別名稱「Gold American Eagles」有一個「重量」數組,但「Gold American Buffalos」沒有重量數組(1個多級數組少)...所以這是一個問題。所有類別名稱應該具有相同的結構... – LoicTheAztec
嗯,這是它在網站上爬行的方式,一些結果會回來,有些類別不會有。 PHP不會按名稱標識數組? – AaronS
我的歉意!這裏是:http://gold.explorethatstore.com/wp-content/themes/divi-ETS-child-theme/run_results_bgasc_gold.json – AaronS