WordPress JSON Rest API

  1. <?php
  2.  
  3.  
  4. $auth = base64_encode("x:y");
  5. $context = stream_context_create(['http' => ['header' => "Authorization: Basic $auth"]]);
  6. $result = file_get_contents("https://kb.innocom.vn/wp-json/wp/v2/users?per_page=100", false, $context );
  7. // echo $result;
  8.  
  9. $result = file_get_contents("https://kb.innocom.vn/wp-json/wp/v2/posts?author=2&status=publish&per_page=100", false, $context );
  10.  
  11. echo "<pre>";
  12. echo var_dump(json_decode($result));
  13. echo "</pre>";

Leave a Reply

You must be logged in to post a comment.