获取 json 匹配高级自定义字段的数据

Get json data that matches advanced custom field

我正在尝试从 json 文件中获取数据以加载到我的 wordpress 站点中。我想从我爬取的站点产品的匹配名称中获取价格。我需要产品的名称来匹配我添加到产品页面的值高级自定义字段我添加到 wordpress 上的产品页面然后如果名称与我添加的属性匹配则获取价格。下面的代码部分起作用,但由于某种原因,对高级自定义字段值的调用不起作用。它显示文本的值,而不是将其与 json 中的名称字段匹配。有什么建议吗?

$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;

您提供的 JSON Url 未返回 JSON,当前返回 404。

此外,我们看不到 product_attribute 的值是什么,因为它是从数据库返回的。

如果你可以 JSON the_field 值并输入 public url.

一旦我们有了这两个数据集,就应该很容易弄清楚为什么 $value name 不等于 product_attribute.