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 Get Featured Image URL

WordPress Tutorial WP REST API Get Featured Image URL in a Post

wp rest api v2

WP REST API Get Posts By Category

WordPress REST API tutorial get posts by category id with php script

wp rest api v2

WP REST API Create Category PHP cURL

Wordpress Tutorial WP REST API V2 Create Category With PHP cURL with code example

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

WP REST API Get Posts By Tag

Wordpress WP REST API Tutorial Get Posts By Tag with php script