Arkadaşlar php kod örneğim:
<?php
$domain = $_SERVER['SERVER_NAME'];
$tags = array(1, 2);
$data = array(
'title' => 'Deneme Makale',
'content' => 'Deneme yazı',
'status' => 'publish',
'categories' => array(1, 2),
'tags' => $tags
);
$data_string = json_encode($data);
$ch = curl_init("http://$domain/wp-json/wp/v2/posts");
$headers = array(
'Authorization: Basic ' . base64_encode('admin:123456789'),
'Content-Type: application/json',
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$error = curl_error($ch);
echo 'Error: ' . $error;
} else {
$result = json_decode($response, true);
print_r($result);
}
curl_close($ch);
geri dönen:
Array ( [code] => rest_cannot_create [message] => Sorry, you are not allowed to create posts as this user. [data] => Array ( [status] => 401 ) )
htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress