正如已经指出的,通过tax_input
参数到wp_insert_post()
您需要让用户登录。在您的情况下,试图从shell执行此操作是没有用的。
或者,您可以使用XML-RPC创建post。
// Function to post to WordPress using XML-RPC
function wp_post_xmlrpc( $username, $password, $rpc_url, $title, $body, $post_type, $categories ) {
$title = htmlentities( $title, ENT_NOQUOTES, \'UTF-8\' );
$content = array(
\'title\' => $title,
\'description\' => $body,
\'mt_allow_comments\' => 0, // 1 to allow comments
\'mt_allow_pings\' => 0, // 1 to allow trackbacks
\'post_type\' => $post_type,
\'categories\' => array( $categories ),
);
$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, $rpc_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$results = curl_exec($ch);
curl_close($ch);
return $results; // Returns the ID of the post
}
$example_post = wp_post_xmlrpc( \'username\', \'password\', \'http://www.mysite.com/xmlrpc.php\', \'Example XML-RPC Post\', \'This is an example post using XML-RPC\', \'post\', array( \'category_one\', \'category_two\', \'category_three\' ) );
echo $example_post; // Echoes out the ID of the post
代码和示例应该是非常自我记录的。