ccc

API REST: Añadir una nueva página

if (isset($arr->token)) {
echo "TOKEN:".$arr->token."<hr>";
$authorization = "Authorization: Bearer ".$arr->token;
$data = array('title' => 'Página creada dinamicamente', 'content' => 'Esto va a ser una página creada dinámicamente, a ver si funciona', 'status' => 'publish');
$data_string = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://midominio.com/wp-json/wp/v2/pages");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization ));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $result = curl_exec($ch);

}

No hay comentarios:

Publicar un comentario