Last active
February 11, 2016 19:46
-
-
Save luisgagocasas/d23ae241a4d6d94c3b25 to your computer and use it in GitHub Desktop.
Leer una API REST de wordpress desde PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//PRIMERA OPCION - funciones nativas php | |
//Optengo la API REST | |
$url = "http://localhost/wordpress/?page_id=2&json=1"; | |
$data = file_get_contents($url); | |
$json = json_decode($data); | |
//Muestro los resultados | |
echo "<p>".$json->status."</p>"; | |
echo "<p>".$json->page->id."</p>"; | |
echo "<p>".$json->page->title."</p>"; | |
//SEGUNDA OPCION - usando libreria curl | |
$url = "http://localhost/wordpress/?page_id=2&json=1"; | |
$rCURL = curl_init(); | |
curl_setopt($rCURL, CURLOPT_URL, $url); | |
curl_setopt($rCURL, CURLOPT_HEADER, 0); | |
curl_setopt($rCURL, CURLOPT_RETURNTRANSFER, 1); | |
$aData = curl_exec($rCURL); | |
curl_close($rCURL); | |
$json = json_decode ($aData); | |
//Muestro los resultados | |
echo "<p>".$json->status."</p>"; | |
echo "<p>".$json->page->id."</p>"; | |
echo "<p>".$json->page->title."</p>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment