Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create new post with photo attached in WordPress using XMLRPC?
    primarykey
    data
    text
    <p><strong>Anyone knows how to create new post with photo attached in WordPress using XMLRPC?</strong> </p> <p>I am able to create new post and upload new picture separately, but looks like there is no way to attach the uploaded photo to the created post? </p> <p>Below is the codes I'm currently using.</p> <pre><code>&lt;?php DEFINE('WP_XMLRPC_URL', 'http://www.blog.com/xmlrpc.php'); DEFINE('WP_USERNAME', 'username'); DEFINE('WP_PASSWORD', 'password'); require_once("./IXR_Library.php"); $rpc = new IXR_Client(WP_XMLRPC_URL); $status = $rpc-&gt;query("system.listMethods"); // method name if(!$status){ print "Error (".$rpc-&gt;getErrorCode().") : "; print $rpc-&gt;getErrorMessage()."\n"; exit; } $content['post_type'] = 'post'; // post title $content['title'] = 'Post Title '.date("F j, Y, g:i a"); // post title $content['categories'] = array($response[1]['categoryName']); // psot categories $content['description'] = '&lt;p&gt;Hello World!&lt;/p&gt;'; // post body $content['mt_keywords'] = 'tag keyword 1, tag keyword 2, tag keyword 3'; // post tags $content['mt_allow_comments'] = 1; // allow comments $content['mt_allow_pings'] = 1; // allow pings $content['custom_fields'] = array(array('key'=&gt;'Key Name', 'value'=&gt;'Value One')); // custom fields $publishBool = true; if(!$rpc-&gt;query('metaWeblog.newPost', '', WP_USERNAME, WP_PASSWORD, $content, $publishBool)){ die('An error occurred - '.$rpc-&gt;getErrorCode().":".$rpc-&gt;getErrorMessage()); } $postID = $rpc-&gt;getResponse(); echo 'POST ID: '.$postID.'&lt;br/&gt;'; if($postID){ // if post has successfully created $fs = filesize(dirname(__FILE__).'/image.jpg'); $file = fopen(dirname(__FILE__).'/image.jpg', 'rb'); $filedata = fread($file, $fs); fclose($file); $data = array( 'name' =&gt; 'image.jpg', 'type' =&gt; 'image/jpg', 'bits' =&gt; new IXR_Base64($filedata), false // overwrite ); $status = $rpc-&gt;query( 'metaWeblog.newMediaObject', $postID, WP_USERNAME, WP_PASSWORD, $data ); echo print_r($rpc-&gt;getResponse()); // Array ( [file] =&gt; image.jpg [url] =&gt; http://www.blog.com/wp-content/uploads/2011/09/image.jpg [type] =&gt; image/jpg ) } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload