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 Upload Image Media

Wordpress WP REST API V2 tutorial and code example upload image / media with PHP cURL

wp rest api v2

WP REST API Get Post By Id With PHP

WordPress WP REST API V2 Tutorial get post by post id using php script.

wp rest api v2

WP Rest API V2 Introduction

WP Rest API V2 Introduction. WordPress is one of the most used content management system (CMS) in the world.

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 Category

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