Last active
November 13, 2016 03:36
-
-
Save jmarreros/4e927b3cdd3eff79b611e115ed086d4a to your computer and use it in GitHub Desktop.
Creación de Entrada usando WP REST API
This file contains 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 | |
$host = 'http://tudominio.com/wp-json/wp/v2/posts/'; | |
$data = array('title' => 'Titulo Post Nuevo', 'content' => 'Contenido nueva entrada', 'status' => 'publish'); | |
$data_string = json_encode($data); | |
$headers = array( | |
'Content-Type:application/json', | |
'Content-Length: ' . strlen($data_string), | |
'Authorization: Basic '. base64_encode('admin:clave') | |
); | |
$ch = curl_init($host); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
echo($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment