Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XML-RPC WordPress API和带有类别的Python发布帖子_Python_Wordpress_Xml Rpc_Categories - Fatal编程技术网

使用XML-RPC WordPress API和带有类别的Python发布帖子

使用XML-RPC WordPress API和带有类别的Python发布帖子,python,wordpress,xml-rpc,categories,Python,Wordpress,Xml Rpc,Categories,我正在从一个网站迁移到另一个使用Wordpress的网站 我根据自己的需要创建了新的自定义类型(使用插件自定义帖子类型),并为每个自定义类型创建了类别 然后,我用Python编写了一个脚本(改编自),该脚本从db获取帖子,并使用3.4.x版以来支持的新WordPressXML-RPC API将其远程推送到新的(测试)网站上 目前,我可以发布一篇具有正确帖子类型的新帖子。但如果我指定了一个类别,wordpress总是会返回以下错误: xmlrpclib.Fault: <Fault 401:

我正在从一个网站迁移到另一个使用Wordpress的网站

我根据自己的需要创建了新的自定义类型(使用插件自定义帖子类型),并为每个自定义类型创建了类别

然后,我用Python编写了一个脚本(改编自),该脚本从db获取帖子,并使用3.4.x版以来支持的新WordPressXML-RPC API将其远程推送到新的(测试)网站上

目前,我可以发布一篇具有正确帖子类型的新帖子。但如果我指定了一个类别,wordpress总是会返回以下错误:

xmlrpclib.Fault: <Fault 401: 'Sorry, one of the given taxonomies is not supported by the post type.'>
在调用者上,指定类别:

new_post['categories'] = [ { 'term_id': 3, 'taxonomy': 'news-cat' } ]
“news cat”是与自定义类型“news”关联的分类法的名称。“term id”是类别的id,我使用phpMyAdmin找到了它

我也尝试过其他方法,但都没有用。没有类别,它工作得很好

提前感谢您的帮助:)

说:

这意味着terms和terms\u名称是目录,key name是所需分类的名称,值是数组列表

如果要设置类别,则应设置

‘terms‘:{‘my-category’:[4]} 

在post结构中,“我的类别”是分类法的名称


一些信息来自:

关于这个特定问题的文档非常糟糕。谢谢分享!这是非常有用的!您好,我一直在寻找一种使用wp.newpost设置分类法父级的方法,但我找不到它(我已经发布了一个没有答案的问题),因此如果有人能帮助我,我将不胜感激。ThanksI无法使此示例正常工作。我总是得到错误:“”。有人有python的工作示例吗?这里有一个python的工作示例:
post.terms_name={'post_tag':['test','firstpost'],'category':['Introductions','Tests']}
在“Introductions”和“Tests”类别下发布文章
struct terms: Taxonomy names as keys, array of term IDs as values.
struct terms_names: Taxonomy names as keys, array of term names as values.
‘terms‘:{‘my-category’:[4]} 
‘terms_names’:{‘my-category’:["Wordpress"]}