首页 > 解决方案 > 从受wordpress保护的数组中获取值

问题描述

我已经使用 API 调用wp_remote_post并使用wp_remote_retrieve_body. 但问题是响应正文受 WordPress 保护。我曾尝试使用反射方法和子类方法来检索数据,但失败了。

下面的代码,我用来进行 API 调用和检索数据。

$response = wp_remote_post ( 'https://apiurl.com?APIKEY='."$api_key".'', $args );
    $response = json_decode(wp_remote_retrieve_body($response), true);

    class my_request_utility {
        protected $response;

        public function test() {
        var_dump(get_object_vars($this->response));
    }
    }
    $my_array = new my_request_utility;
    var_dump(get_object_vars($my_array));
    $my_array->test();
    $currencyData = wp_remote_retrieve_body( $currency );
    $responceData = $my_array;

    $str = '';
    foreach ($responceData->MenuList as $Item)
    {
        $str .= '<table width="100%" height="auto" border="0px solid #FFFFFF">
        <tr>
        <td width="80%" class="cat">'.$Item['Name'].'</td>
        <td width="20%" align="center" class="cat">
          <a target="_blank" href="'.$ulr.'">ORDER</a>
        </td>
        </tr>';
        foreach($Item['Item'] as $Value)
        {
            $str .= '<tr>
                      <td class="item" width="80%">'.$Value['Price'].'</td>
                      <td class="item" align="center" width="20%"><b>'.$Value['Price'].'</b></td>
                  </tr>';
        }
        $str .= '</table>';    
    }

现在我收到这些错误。

get_object_vars() 期望参数 1 是对象,给定 null

未定义的属性:my_request_utility::$MenuList

为 foreach() 提供的参数无效

请帮我。我已经用不同的方法尝试了三天,但失败了。

标签: phpwordpress

解决方案


推荐阅读