fork download
  1. <?php
  2. // Function to make GET request to WordPress REST API
  3. function get_posts($url) {
  4. $ch = curl_init();
  5.  
  6. curl_setopt($ch, CURLOPT_URL, $url);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  8.  
  9. // Optional: Set headers if needed
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  11. 'Content-Type: application/json',
  12. 'Authorization: Bearer YOUR_ACCESS_TOKEN' // For authenticated requests
  13. ]);
  14.  
  15. $response = curl_exec($ch);
  16. curl_close($ch);
  17.  
  18. return json_decode($response, true);
  19. }
  20.  
  21. // Example usage
  22. $posts = get_posts('https://j...content-available-to-author-only...s.systems/wp-json/wp/v2/posts');
  23. print_r($posts);
  24.  
  25. ?>
  26.  
  27.  
Success #stdin #stdout 0.03s 26328KB
stdin
Standard input is empty
stdout