我是否可以在我的WordPress网站上发布帖子而无需登录管理面板。我想要一个表格,我可以写帖子标题,帖子正文,作者ID和发布按钮。我想使用MySQL数据库连接,所以我不需要每次登录都要登录。此表单将在我的本地主机上并与我的WordPress数据库连接。当我填写此表单时,它应该在数据库中添加帖子并在我的网站上发布。
答案 0 :(得分:2)
有WP REST API和JSON API可用。 请使用此插件,您可以从文字外部发帖。
答案 1 :(得分:0)
您可以使用以下插件从正面创建帖子。
答案 2 :(得分:0)
Find PHP Code for calling Json API
PHP HTML V2
<?php
$client = new http\Client;
$request = new http\Client\Request;
$body = new http\Message\Body;
$body->append('[{
"Id": "",
"date" : "11-May-2016",
"title" : "Post from API",
"content" : "My first post",
"excerpt" : ""
}]');
$request->setRequestUrl('http://localhost/wp-json/wp/v2/posts/');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders(array(
'postman-token' => 'a2a42c5a-002f-fc4e-15ea-4d734761f608',
'cache-control' => 'no-cache'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
PHP HTML V1
<?php
$request = new HttpRequest();
$request->setUrl('http://localhost/wp-json/wp/v2/posts/');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array(
'postman-token' => 'f421932b-cc55-5306-8fb3-5ca7bba3dd1d',
'cache-control' => 'no-cache'
));
$request->setBody('[{
"Id": "",
"date" : "11-May-2016",
"title" : "Post from API",
"content" : "My first post",
"excerpt" : ""
}]');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}