网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

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

GG网络技术分享 2025-03-18 16:12 2


问题描述:

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

图片转代码服务由CSDN问答提供

感谢您的意见,我们尽快改进~

功能建议

我正在寻找从不同服务器上的php脚本发布到wordpress博客的最佳解决方案。

Is 有没有开发好的PHP脚本?

我认为它不适用于像WP REST API这样的cookie auth模型吗?</ p>

非常感谢</ p>

< p>问候</ p>

memme </ p>

</ div>

网友观点:

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\'];

标签:

提交需求或反馈

Demand feedback