I am trying to post to my wordpress site by xml-rpc.
I have two problem about the turkish charcters.
1 – When i use one of theese characters (Çç,Ğğ,Iı,Öö,Şş,Üü) in the title sends a post to wordpress without title.?
2 – And when i use form same charcters in body content it sends in different form.
For example in body content i have “Ankaralıyım” an dit goes to wordpress as “Ankaralýyým“.
Here is the code I use
<?php
$title="Karaçay";
$body="Ankaralıyım";
$rpcurl="http://localhost/wp/xmlrpc.php";
$username="admin";
$password="pass";
$categories="try";
echo wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories,'');
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8')
{
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
$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',
'mt_keywords'=>$keywords,
'categories'=>array($category)
);
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params, array('encoding'=>'UTF-8'));
$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;
}
?>
I do not have any language problem when i add the post from wordpress.
How i will fix this?
And i have tried the same thing with different code and this time if there was any turkish character in the title or post I got this result
Error while creating a new post-32700 : parse error. not well formed
Second code is
<?php
require("class-IXR.php");
$client = new IXR_Client('http://localhost/wp/xmlrpc.php');
$USER = 'admin';
$PASS = 'pass';
$content['title'] = 'Test title '.mt_rand();
$content['categories'] = array("NewCategory","Nothing");
$content['description'] = '<p>Lorem ırmak ipsum dolor sit amet</p>';
$content['custom_fields'] = array( array('key' => 'my_custom_fied','value'=>'yes') );
$content['mt_keywords'] = array('foo','bar');
if (!$client->query('metaWeblog.newPost','', $USER,$PASS, $content, true))
{
die( 'Error while creating a new post' . $client->getErrorCode() ." : ". $client->getErrorMessage());
}
$ID = $client->getResponse();
if($ID)
{
echo 'Post published with ID:#'.$ID;
}
?>
This was the two different way to send post to wordpress by xml-rpc. But chacters different than english doesnt work. What i know there is utf-8 support of xml-rpc.
- I have already checked many sites and there was a solution with dead link.
dead link is http://thr.gen.tr/php/xmlrpc-turkce-karakter-sorunu.html
You should add
escaping->markupparameter toxmlrpc_encode_request: