![WordPress](https://stat.ameba.jp/user_images/20120518/15/linking/33/35/p/t02200137_0499031011979397092.png?caw=800)
ワードプレスで管理画面以外から記事の投稿・編集・削除を行う方法
管理画面以外の外部サイトやページから記事の追加・編集・削除を行うには以下の関数を使うとできます。記事の投稿
記事の投稿関数: wp_insert_post
// 投稿オブジェクトの作成
$my_post = array();
$my_post['post_title'] = 'My post';
$my_post['post_content'] = 'This is my post.';
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array(8,39);
// データベースに投稿を追加
wp_insert_post( $my_post );
記事の編集
記事の編集関数: wp_update_post
// ID が37の投稿を更新します
$my_post = array();
$my_post['ID'] = 37;
$my_post['post_content'] = 'これの本文は更新されました。';
// データベースの投稿情報を更新
wp_update_post( $my_post );
記事の削除関数
記事の削除: wp_delete_post
wp_delete_post( $postid, $force_delete = false )