0

I'm trying to create/update wordpress custom posts using xml-rpc. The post includes some serialized fields such as location data:

a:2:{s:3:"lat";s:2:"51";s:3:"lng";s:3:"-3.2";}

I'm using php xmlrpc_encode_request which is "experimental". If I send the serialized string then wordpress serializes it again and I end up with a serialized string:

s:46:"a:2:{s:3:"lat";s:2:"51";s:3:"lng";s:3:"-3.2";}";

and I haven't found any combination of arrays or objects that will parse to a valid wordpress serialized field.

Can anyone point me in the right direction? Is this a wordpress xml-rpc bug, an issue with xmlrpc_encode_request or just me being a numpty?

Thanks

Basically I'm doing this:

$content=array();
$custom_fields=array();

$gps=array("latitude"=>"$lat","longitude"=>"$lng");
//do something in here so that xmlrpc will encode the array correctly

$custom_fields[]=array("key"=>"_post_location", "value"=>$gps);
$content['post_title']="the title";
$content['post_status']='publish';
$content['post_content']="the content";
$content['custom_fields]=$custom_fields;
$request = xmlrpc_encode_request( "wp.newPost", array( 0, $username, $password, $content));

//then send request to xmlrpc.php

No matter how I try to encode, serialize or unserialize the custom field array $gps it does not get encoded by xmlrpc.php correctly. I either get a serialized string or an empty field.

  • `unserialize()` needs to be used on the string before using `xmlrpc_encode`. – l'L'l Jul 30 '14 at 00:47
  • unserialize() does not work for this. – user3889393 Jul 30 '14 at 12:01
  • You're missing a `'` at the end of `$content['custom_fields <--` after minor changes it works: http://phpfiddle.org/lite/code/whgx-yaz9. Which version of PHP are you using? – l'L'l Jul 30 '14 at 16:52
  • Thanks but your code works exactly the same as mine (I don't have the typos). When you actually post this request to wordpress xmlrpc.php it does not parse the field and I end up with an empty value for _post_location in the database???? – user3889393 Jul 30 '14 at 17:09
  • update: I found the issue, it was in my sanitize function under register_meta thanks for your input though. – user3889393 Jul 30 '14 at 18:31

0 Answers0