Where would I put my call to wp_remote_get?

I’m guessing I should make a function that: Calls wp_remote_get(“https://jsonplaceholder.typicode.com/todos”) Returns the array of job posting objects Yes, that still leaves the question of where to call it in functions.php, but I’m not sure how I would export it so it would be available in the view. Functions in functions.php are available in templates, making … Read more

rewrite script to use wp_remote_get instead of file_get_contents_curl

You can try this: foreach( $posts as $post ) { $url = sprintf( ‘http://graph.facebook.com/?id=%s’, get_permalink( $post->ID ) ); $response = wp_remote_get( $url, array( ‘timeout’ => 15 ) ); if( ! is_wp_error( $response ) && isset( $response[‘response’][‘code’] ) && 200 === $response[‘response’][‘code’] ) { $body = wp_remote_retrieve_body( $response ); $fb = json_decode( $body ); if( ! … Read more

wp_remote_get(), downloading and saving files

Well here’s the solution that I came up with: // Use wp_remote_get to fetch the data $response = wp_remote_get($url); // Save the body part to a variable $zip = $data[‘body’]; // In the header info is the name of the XML or CVS file. I used preg_match to find it preg_match(“/.datafeed_([0-9]*)\../”, $response[‘headers’][‘content-disposition’], $match); // Create … Read more

tech