Wordpress API submit post Wordpress API submit post wordpress wordpress

Wordpress API submit post


You could use the XML-RPC API to do this, here is an simple example using curl which creates a new post using wp.newPost:

// initialize curl$ch = curl_init();// set url ie path to xmlrpc.phpcurl_setopt($ch, CURLOPT_URL, "http://www.example.com/xmlrpc.php");// xmlrpc only supports post requestscurl_setopt($ch, CURLOPT_POST, true);// return transfearcurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);// setup post data$content = array(  'post_type' => 'post',  'post_content' => 'This is the post content',  'post_title' => 'This is the post title',  'post_status' => 'publish',);// parameters are blog_id, username, password and content$params = array(1, '<user>', '<password>', $content);$params = xmlrpc_encode_request('wp.newPost', $params);curl_setopt($ch, CURLOPT_POSTFIELDS, $params);// execute the requestcurl_exec($ch);// shutdown curlcurl_close($ch);

To get a list of posts you may use wp.getPosts, although you cannot filter posts by author, you could loop through each post in the response and check if it should be displayed or not:

// filter used when retrieving posts$filter = array(  'post_type' => 'post',  'post_status' => 'publish',  'number' => 50,  'offset' => 0,  'orderby' => 'post_title',);// fields to include in response$fields = array(  'post_title',  'post_author',  'post_id',  'post_content',);$params = array(1, '<username>', '<password>', $filter, $fields);$params = xmlrpc_encode_request('wp.getPosts', $params);curl_setopt($ch, CURLOPT_POSTFIELDS, $params);// execute query$response = curl_exec($ch);// response is xml$response = simplexml_load_string($response);// walk over response and figure out if post should be displayed or not


I know enough about WP to know better than to use it.

But you do not need any of the stuff you are considering e.g. nonce, IXR, XML.

You write your own PHP script. I do not understand why you need a remote blog post tool when websites by their nature are remotely accessible. Like use a bookmark to your WP site.

I can see some possible uses for getting a list of posts.

Why would you need security to access posts that are there for the public to see?

Script on WP site:

header('Content-Type: text/plain; charset=utf-8');$rows = 0;$date = date('Y-m-d',strtotime($_GET['date'])) . '00:00:00';$results=mysqli_query("SELECT`comment_post_ID`,`comment_date`,`comment_content`    FROM `wp_comments` WHERE `comment_date` > '$date'   ORDER BY `comment_post_ID` ASC,`comment_date` ASC);while ($pats = mysqli_fetch_array($results, MYSQL_NUM)){  echo "$row[0]\t$row[1]\r\n";}echo "$rows\trows\n";

Access from Browser:

http://wp_site.com/script.php?date=m/d/y'

Script accessed from remote PHP script:

header('Content-Type: text/plain; charset=utf-8');$data = file_get_contents('http://wp_site.com/script.php?date=m/d/y');$fp = fopen('posts.csv');fwrite($fp,$data);fclose($fp);echo $data

If you do not want to save a copy of data in file

header('Content-Type: text/plain; charset=utf-8');echo file_get_contents('http://wp_site.com/script.php?date=m/d/y');