Skip to content

Instantly share code, notes, and snippets.

@nobodyplace
Last active July 10, 2019 12:40
Show Gist options
  • Select an option

  • Save nobodyplace/5d6b04b9c186a07dace7a71034d7c3df to your computer and use it in GitHub Desktop.

Select an option

Save nobodyplace/5d6b04b9c186a07dace7a71034d7c3df to your computer and use it in GitHub Desktop.
<?php
$client = new \GuzzleHttp\Client([
'base_uri' => 'https://example.com/wp-json/wp/v2/'
]);
$response = $client->get('media',[
'query' => ['search' => 'sample']
]);
$result = json_decode($response->getBody()->getContents());
return (count($result)) ? $result[0]->id : null;
<?php
$client = new \GuzzleHttp\Client([
'base_uri' => 'https://example.com/wp-json/wp/v2/'
]);
$response = $client->get('media',[
'query' => ['title' => 'sample']
]);
$result = json_decode($response->getBody()->getContents());
return (count($result)) ? $result[0]->id : null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment