Skip to content

Instantly share code, notes, and snippets.

@fernandiez
Created May 31, 2019 05:15
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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