检查文档。file_get_contents()
和wp_remote_get()
不等同。file_get_contents()
返回字符串。wp_remote_get()
返回数组或WP_Error
对象你需要看看wp_remote_post()
to see the format of that array:
Array
(
[headers] => Array
(
[date] => Thu, 30 Sep 2010 15:16:36 GMT
[server] => Apache
[x-powered-by] => PHP/5.3.3
[x-server] => 10.90.6.243
[expires] => Thu, 30 Sep 2010 03:16:36 GMT
[cache-control] => Array
(
[0] => no-store, no-cache, must-revalidate
[1] => post-check=0, pre-check=0
)
[vary] => Accept-Encoding
[content-length] => 1641
[connection] => close
[content-type] => application/php
)
[body] => <html>This is a website!</html>
[response] => Array
(
[code] => 200
[message] => OK
)
[cookies] => Array
(
)
)
我猜你想要的部分是
body
. 您可能想做这样的事情(非常简单,但很有说明性):
$content = wp_remote_get($query);
if (!is_wp_error($content)) {
$content = json_decode($content[\'body\']);
}