如何使用xml rpc和curl在Wordpress中添加帖子而无需管理员登录
我想在Wordpress站点中添加帖子,使用XMLRPC和curl或任何替代方法,而无需登录WP admin。这是可能的吗?Wordpress中有一个内置功能,允许您使用。虽然从未测试过,但它可能适合您的需要 您可以在站点的管理员中,在“设置”>“编写”(URL类似于如何使用xml rpc和curl在Wordpress中添加帖子而无需管理员登录,wordpress,xml-rpc,posts,Wordpress,Xml Rpc,Posts,我想在Wordpress站点中添加帖子,使用XMLRPC和curl或任何替代方法,而无需登录WP admin。这是可能的吗?Wordpress中有一个内置功能,允许您使用。虽然从未测试过,但它可能适合您的需要 您可以在站点的管理员中,在“设置”>“编写”(URL类似于http://yourwordpresssite.com/wp-admin/options-writing.php) 但是,如果您需要API,您可以在Wordpress Codex页面中找到与和相关的有用内容 对于代码示例,您可以看
http://yourwordpresssite.com/wp-admin/options-writing.php
)
但是,如果您需要API,您可以在Wordpress Codex页面中找到与和相关的有用内容
对于代码示例,您可以看一看,这对我来说似乎是一个很好的基础。我得到了答案,下面的代码对我很有用
function wpPostXMLRPC ($title,$body,$rpcurl,$username,$password,$category='Uncategorized',$keywords='',$encoding='UTF-8') {
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
$content = array (
'title'=>$title,
'description'=>$body,
'mt_allow_comments'=>0,
'mt_allow_pings'=>0,
'post_type'=>'post',
'mt_keywords'=>$keywords,
'categories'=>array(
$category
)
);
$params = array(
0,
$username,
$password,
$content,
true
);
$request = xmlrpc_encode_request('metaWeblog.newPost', $params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
}
$title = 'post-title';
$body = 'POST BODY WILL GOES HERE';
$rpcurl = 'http://example.com/xmlrpc.php';
$username = 'xxx';
$password = 'xxx';
$category = 'test';
$chk = wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8');
if($chk) {
echo $chk;
} else {
echo 'failed';
}
有没有办法在wordpress之外使用PHP在wordpress中创建图库?谢谢