dsd57259 2018-07-03 13:00
浏览 271
已采纳

使用php远程发布到Wordpress博客(最佳解决方案)

I am searching for the best solution to post to a wordpress blog from a php script on a different server. Is there any good php script already developed? I think it would not work with a cookie auth model like the WP REST API?

Thank you very much

Regards

memme

  • 写回答

1条回答 默认 最新

  • douchui7332 2018-07-03 18:26
    关注

    Think best solution is to use the XML-RPC of wordpress with this PHP client: https://github.com/letrunghieu/wordpress-xmlrpc-client

    Here is the code to add a new Wordpress Blog Post and retrieve the 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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料