<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AB-WebLog.com&#187; XML-RPC</title>
	<atom:link href="http://www.ab-weblog.com/en/tag/xml-rpc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ab-weblog.com/en</link>
	<description>Andreas Breitschopp</description>
	<lastBuildDate>Wed, 18 Mar 2015 09:47:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Create New Posts With Publishing Date in WordPress Using XML-RPC and PHP</title>
		<link>http://www.ab-weblog.com/en/create-new-posts-with-publishing-date-in-wordpress-using-xml-rpc-and-php/</link>
		<comments>http://www.ab-weblog.com/en/create-new-posts-with-publishing-date-in-wordpress-using-xml-rpc-and-php/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 17:51:00 +0000</pubDate>
		<dc:creator>Andreas Breitschopp</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[ISO 8601]]></category>
		<category><![CDATA[XML-RPC]]></category>

		<guid isPermaLink="false">http://www.ab-weblog.com/en/?p=215</guid>
		<description><![CDATA[To be able to add new posts to a WordPress blog I wanted to use XML-RPC interface with PHP. First of all you need to enable the checkbox &#8220;Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols.&#8221; in &#8230; <a href="http://www.ab-weblog.com/en/create-new-posts-with-publishing-date-in-wordpress-using-xml-rpc-and-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To be able to add new posts to a WordPress blog I wanted to use XML-RPC interface with PHP.</p>
<p>First of all you need to enable the checkbox &#8220;Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols.&#8221; in the menu &#8220;Settings&#8221;/&#8221;Writing&#8221;.</p>
<p>Now I searched on the web for a ready-to-use solution as I was probably not the first one who wanted to accomplish that. And as expected there were also many PHP scripts doing exactly that, but with one problem:<br />
I wanted to set also the publishing date manually with the PHP request and most scripts I&#8217;ve found did not even try to do that at all.</p>
<p>Few scripts in fact did try to set the publishing date, but the result was an error message similar to:<br />
<strong>Fatal error</strong>: Call to a member function getIso() on a non-object in <strong>/var/www/wp-includes/class-wp-xmlrpc-server.php</strong> on line <strong>2373</strong></p>
<p>After reading some documents regarding this strange ISO 8601 date format that is needed there, I found a solution myself:</p>
<pre class="brush: php; gutter: true">/**
 * Performs a XML-RPC to a WordPress blog and adds a new post.
 *
 * @param string $title Title of the new post.
 * @param string $body Body text of the new post.
 * @param string $rpcurl RPC-URL of the blog (normally xmlrpc.php in the root directory).
 * @param string $username User name used to add the new post.
 * @param string $password Password used to add the new post.
 * @param string $categories Comma separated list of categories (make sure they already exist in your blog).
 * @param string $keywords Comma separated list of keywords/tags (in contrast to the categories they don't need to exist already).
 * @param string $pubdate Publishing date in ISO 8601 (with date('c') in PHP; current time is used if empty).
 * @param string $draftonly True to save as draft only, False to publish directly (default).
 * @return string The result of the XML-RPC.
 */
function wpPostXMLRPC($title, $body, $rpcurl, $username, $password, $categories, $keywords = '', $pubdate = '', $draftonly = false) {
	$content = array(
		'title' =&gt; $title,
		'description' =&gt; $body,
		'mt_allow_comments' =&gt; 1,
		'mt_allow_pings' =&gt; 1,
		'post_type' =&gt; 'post',
		'date_created_gmt' =&gt; '%pubdate%', // Just as place holder here.
		'mt_keywords' =&gt; $keywords,
		'categories' =&gt; array($categories)
	);
	$params = array(0, $username, $password, $content, !$draftonly);

	$request = xmlrpc_encode_request('metaWeblog.newPost', $params);
	// Now we need to set the real publishing date:
	$request = str_replace('&lt;string&gt;%pubdate%&lt;/string&gt;',
			       '&lt;dateTime.iso8601&gt;' . $pubdate . '&lt;/dateTime.iso8601&gt;',
			       $request);

	$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;
}</pre>
<p>As you can see I inserted the data structure needed for the correct ISO 8601 date format myself directly into the XML request. This is probably not the most elegant way, but it works perfectly. <img src='http://www.ab-weblog.com/en/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><em>Did you come across the same issue already yourself?</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ab-weblog.com/en/create-new-posts-with-publishing-date-in-wordpress-using-xml-rpc-and-php/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->