<?php
$url = 'http://localhost/demoproject/api/get_posts/';
$json = wp_remote_get($url);
$json_body = wp_remote_retrieve_body($json);
$data = json_decode($json_body, true);
/*echo "<pre/>";
print_r($data);*/
//$parsed['posts']['id'];
// Check if posts array exists and it is not empty
if (isset($data['posts']) && !empty($data['posts'])) {
foreach ($data['posts'] as $post) {
echo '<h2>' . $post['title'] . '</h2> <br/>';
echo '<p>' . $post['content'] . '</p> <br/>';
echo '<p>Date: ' . $post['date'] . '</p><br/>';
echo '<p>Author: ' . $post['author']['name'] . '</p>';
echo '<p>Author: ' . $post['author']['first_name'] . '</p>';
echo '<p>Author: ' . $post['author']['last_name'] . '</p>';
echo '<hr>';
}
} else {
echo 'No posts found.';
}
//foreach ($listings as $listing){ //insert data into custom fields}
?>