WP REST API Get Media Detail By ID

By | May 21, 2017

WP REST API V2 Get Media Details by media id.

Beside post and taxonomy WP REST API also has functions in media library. We can view , edit , create ( upload ) and delete media. Bellow there is a code example wp rest api v2 view media / attachment details by it’s id.

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://localhost/wp/wp-json/wp/v2/media/269");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
 echo "cURL Error #:" . $err;
} else {
 echo '<pre>'.print_r(json_decode($response, true), true).'</pre>';
}

 

If your api request is valid you will see JSON response about media information.

Related Posts

WP REST API V2 Auth

WP REST API Create Comment Into A Post

Wordpress Tuorial WP REST API Create Comment Into A Post.

WP REST API V2 Auth

WP REST API Create Post With PHP cURL

Create post in WP REST API V2 with PHP cURL. Wordpress tutorial creating post with WP REST API / WP-JSON using PHP cURL script.

WP REST API V2 Auth

WP REST API Edit Post PHP cURL

Wordpess Tutorial WP REST API V2 Update Post by post id with PHP cURL

WP REST API V2 Auth

Autocomplete WordPress Search Form With WP REST API

WordPress Tutorial Create Autocomplete Search Form Using WP REST API V2 With Code Example

WP REST API V2 Auth

WP REST API Basic Authentication With PHP Curl

Wordpress Tutorial WP REST API Basic Authentication With PHP Curl