admin管理员组文章数量:1026989
I have this code that inserts a post into WordPress site using Rest API:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $row->site_url."/wp-json/wp/v2/posts");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$row->token
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"title"=>$row->title,
"content"=>$row->content,
"excerpt"=>$row->excerpt,
"status"=>'publish',
"categories"=>(int)$row->c_wp_id
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$result_decoded = json_decode($result);
$post_id=$result_decoded->id;
I need to add meta , how do I do that?
I have tried this but it's not saving the meta:
$tst = (object)array(
'some_key' => 'some_test_again'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $row->site_url."/wp-json/wp/v2/posts/".$row->wp_post_id);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$row->token
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"title"=>$post_array['title'],
"content"=>$post_array['content'],
"excerpt"=>$post_array['excerpt'],
"meta"=>$tst
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$result_decoded = json_decode($result);
$post_id=$result_decoded->id;
I have this code that inserts a post into WordPress site using Rest API:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $row->site_url."/wp-json/wp/v2/posts");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$row->token
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"title"=>$row->title,
"content"=>$row->content,
"excerpt"=>$row->excerpt,
"status"=>'publish',
"categories"=>(int)$row->c_wp_id
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$result_decoded = json_decode($result);
$post_id=$result_decoded->id;
I need to add meta , how do I do that?
I have tried this but it's not saving the meta:
$tst = (object)array(
'some_key' => 'some_test_again'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $row->site_url."/wp-json/wp/v2/posts/".$row->wp_post_id);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$row->token
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"title"=>$post_array['title'],
"content"=>$post_array['content'],
"excerpt"=>$post_array['excerpt'],
"meta"=>$tst
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$result_decoded = json_decode($result);
$post_id=$result_decoded->id;
本文标签: How do I add meta when creating a post with rest api
版权声明:本文标题:How do I add meta when creating a post with rest api? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745628887a2160035.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论