我想添加具有精選圖片的新帖子,但首先要將圖像添加到帖子中。通過api在wordpress.com中添加精選圖片
function add_post($access_key,$blogid,$title,$content,$categories_array,$tags_array,$featuredimage)
{
$options = array (
'http' =>
array (
'ignore_errors' => true,
'method' => 'POST',
'header' =>
array (
0 => 'authorization: Bearer '.$access_key,
1 => 'Content-Type: multipart/form-data',
),
'content' => http_build_query(
array (
'title' => $title,
'content' => $content,
'tags' => $tags_array,
'categories' => $categories_array,
'media'=>$featuredimage,///array($featuredimage),//jak nie zadziala to zapakowac w array
'media[]'=>$featuredimage//array($featuredimage)
)
),
),
);
$context = stream_context_create($options);
$response = file_get_contents(
"https://public-api.wordpress.com/rest/v1/sites/{$blogid}/posts/new/",
false,
$context
);
$response = json_decode($response);
return $response;
}
功能的屍體被從實例複製,只是加入媒體
add_post($_GET['token'],$blog_id,"tytul","tresc",array("cat1"),array("tagt1","tag2"), "http://icons.iconarchive.com/icons/iconka/meow/256/cat-walk-icon.png");
增加崗位工作正常,沒有在文檔中添加圖片
http://developer.wordpress.com/docs/api/1/post/sites/ $網站/職位/新/ 我發現僅用於從控制檯添加媒體的代碼
curl \
--form 'title=Image' \
--form 'media[][email protected]/path/to/file.jpg' \
-H 'Authorization: BEARER your-token' \
'https://public-api.wordpress.com/rest/v1/sites/123/posts/new'
,並提及有關表單內容類型
「(...)要上傳的媒體,整個請求應 的multipart/form-data的」
,但是當我改變「應用/ X WWW的形式,進行了urlencoded」爲‘multipart /改變
你'header'上下文是從[手冊中的示例](http://php.net/manual/en/function.file-不同得到-contents.php)。 – brasofilo
我使用了wordpress.com api的示例http://developer.wordpress.com/docs/api/1/post/sites/%24site/posts/new/ –