wordpressに外部から投稿する
XML-RPCの機能を使う
IXR_Library.phpを使う
<?php
include_once("IXR_Library.php");
$client = new IXR_Client("https://xxx.com/xmlrpc.php");
$wp_username = "namae";
$wp_password = "password";
$status = $client->query(
"wp.newPost", //使うAPIを指定(wp.newPostは、新規投稿)
1, //ブログID 通常は1、マルチサイトの場合は変更が必要
$wp_username, //ユーザー名
$wp_password, //パスワード
array(
"post_author" => 1, //投稿者ID 未指定の場合、投稿者名なしになります
"post_status" => "future", //投稿状態
"post_title" => "これはテスト投稿ですphp", //タイトル
"post_content" => "テスト投稿本文です。", //本文
"terms" => array("category" => array(1)) //カテゴリ
)
);
if(!$status){
die("エラー! - ".$client->getErrorCode()." : ".$client->getErrorMessage());
} else {
$post_id = $client->getResponse(); //返り値は投稿ID
}
