您好我无法使用wp rest api存储作者字段的值。 author是自定义帖子类型book中的自定义字段。所有其他字段都正确存储。它会忽略自定义帖子类型书的所有自定义字段。
<?php
$curl = curl_init();
$data = array(
'title' => "book 1",
'status' => "publish",
'content' => "Inserting data through rest api ",
'format' => 'standard',
'author' => 'Jaipur',
);
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost/wp-json/wp/v2/book/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_USERPWD => "admin" . ":" . "admin",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"Content-Type: application/x-www-form-urlencoded"
),
CURLOPT_POSTFIELDS => http_build_query($data),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
答案 0 :(得分:0)
您需要提及对象作者的ID。不是名字或者什么。 https://developer.wordpress.org/rest-api/reference/posts/#create-a-post