Skip to content

Instantly share code, notes, and snippets.

@fernandiez
Created May 31, 2019 05:15
Show Gist options
  • Save fernandiez/031c22b09e1e80e4c397790a53857e2c to your computer and use it in GitHub Desktop.
Save fernandiez/031c22b09e1e80e4c397790a53857e2c to your computer and use it in GitHub Desktop.
Remote WordPress API REST request
<?php
$uri = 'http://www.dominio.com/wp-json/wp/v2/posts/?page=1&per_page=3';
$json = file_get_contents($uri);
$posts= json_decode($json);
echo "<h1>Listado de entradas</h1><ul>";
foreach ($posts as $post) {
echo "<h2><a href='" . $post->link . "'>" . $post->title->rendered . "</a></h2>\n";
echo "<p>" . $post->excerpt->rendered . "</p>";
echo "<p><a href='" . $post->link . "'>Enlace directo</a></p>\n";
}
echo "</ul>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment