Reputation: 131
I am trying to get data from a json file to be loaded into my wordpress site. I would like to get the price from the matching name of the product of the site that I crawled. I need the name of the product to match the value advanced custom field that I added to the product pages I added into the product page on wordpress then to get the price if the name matches the attribute I added. The code below partially worked, but for some reason the call for the advanced custom field calue is not working. It displays the value of the text instead of matching it to the name field in json Any advice?
$str = file_get_contents('http://gold.explorethatstore.com/wp-content/themes/divi-ETS-child-theme/run_results_apmex.json');
// decode JSON
$json = json_decode($str, true);
// default value
$coinPrice = "No results found";
$product_attribute = the_field('apmex_vendor_name');
// loop the json array
foreach($json['coin'] as $value){
// check the condition
if($value['name'] == $product_attribute){
$coinPrice = $value['price']; // get the price
break; // exit the loop
}
}
echo $coinPrice;
Upvotes: 1
Views: 601
Reputation: 26
The JSON Url you provided is not returning JSON, currently is returning a 404.
Additional we cannot see what the value of product_attribute since it is returned from the database.
If you could JSON the_field value and put in a public url.
Once we have those two datasets, it should be easy to figure out why $value name is not equal to the product_attribute.
Upvotes: 1