Check the docs. file_get_contents()
and wp_remote_get()
are not equivalent. file_get_contents()
returns a string. wp_remote_get()
returns either an array or a WP_Error
object. You need to look at 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
(
)
)
I am guessing that the part you want is the body
. You’d want to do something like this (very minimal but illustrative):
$content = wp_remote_get($query);
if (!is_wp_error($content)) {
$content = json_decode($content['body']);
}