我正在寻找从另一台服务器上的php脚本发布到wordpress博客的最佳解决方案。 有没有已经开发好的PHP脚本? 我认为它无法与WP REST API这样的cookie身份验证模型一起使用?
非常感谢您
致谢
成员
答案 0 :(得分:0)
最好的解决方案是在此PHP客户端上使用wordpress的XML-RPC: https://github.com/letrunghieu/wordpress-xmlrpc-client
以下是添加新的Wordpress Blog Post并检索URL的代码:
require_once 'WordpressClient.php';
require_once('.\Exception\NetworkException.php');
require_once('.\Exception\XmlrpcException.php');
$endpoint = "http://www.example.com/xmlrpc.php";
$wpUser = 'username';
$wpPass = 'password';
$YourCategoryID = 5;
$wpClient = new \HieuLe\WordpressXmlrpcClient\WordpressClient();
$wpClient->setCredentials($endpoint, $wpUser, $wpPass);
$title="Your Blog Post Title";
$title = htmlentities( $title, ENT_NOQUOTES, 'UTF-8' );
$body='Your HTML coded article';
$content = array(
'post_category' => array( $YourCategoryID ), // my category id
'post_type' => 'post',
'post_status' => 'published',
'post_title' => $title,
'post_content' => $body,
'ping_status' => 'closed',
'comment_status' => 'closed',
);
$result=$wpClient->newPost($title,$body,$content);
$postname=$wpClient->getPost($result);
$new_post_url_slug=$postname['post_name'];