php使用xml rpc更新wordpress中的序列化字段
我正在尝试使用xml rpc创建/更新wordpress自定义帖子。 post包含一些序列化字段,如位置数据:php使用xml rpc更新wordpress中的序列化字段,php,wordpress,xml-rpc,Php,Wordpress,Xml Rpc,我正在尝试使用xml rpc创建/更新wordpress自定义帖子。 post包含一些序列化字段,如位置数据: a:2:{s:3:"lat";s:2:"51";s:3:"lng";s:3:"-3.2";} 我正在使用php xmlrpc_encode_请求,这是“实验性的”。 如果我发送序列化字符串,wordpress会再次序列化它,最后我得到一个序列化字符串: s:46:"a:2:{s:3:"lat";s:2:"51";s:3:"lng";s:3:"-3.2";}"; 我还没有发现任何数组
a:2:{s:3:"lat";s:2:"51";s:3:"lng";s:3:"-3.2";}
我正在使用php xmlrpc_encode_请求,这是“实验性的”。
如果我发送序列化字符串,wordpress会再次序列化它,最后我得到一个序列化字符串:
s:46:"a:2:{s:3:"lat";s:2:"51";s:3:"lng";s:3:"-3.2";}";
我还没有发现任何数组或对象的组合可以解析为有效的wordpress序列化字段
谁能给我指出正确的方向吗?
这是WordPressXMLRPC错误,xmlrpc_编码_请求的问题,还是我只是个傻瓜
谢谢
基本上我是这样做的:
$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
无论我如何对自定义字段数组$gps进行编码、序列化或取消序列化,xmlrpc.php都无法正确地对其进行编码。我要么得到一个序列化字符串,要么得到一个空字段。
unserialize()
在使用xmlrpc\u encode
之前需要在字符串上使用。unserialize()不适用于此。在$content[“自定义”字段的末尾缺少一个'
,谢谢,但您的代码与我的代码工作方式完全相同(我没有输入错误)。当您实际将此请求发布到wordpress xmlrpc.php时,它不会解析该字段,而我在数据库中的“发布位置”的值为空???更新:我发现了问题,它出现在我的“注册”下的“清理”函数中。不过,感谢您的输入。