2016-09-23 59 views
1

我有使用蟒蛇的wordpress-XMLRPC的问题时,它会作出新的岗位与预先存在的类别,但有一个错误如下:错误500:提供名称的术语已经存在于此父项中。

Fault: <Fault 500: 'A term with the name provided already exists with this parent.'> 

我用的脚本:

categorys = ['cat_1', 'cat_2'] 
post = WordPressPost() 
post.post_type = 'post' 
post.terms_names = { 'post_tag': categorys, 'category': categorys } 
post.title = title 
post.content = content 
post.post_status = 'publish' 
post.thumbnail = attachment_id 
client.call(posts.NewPost(post)) 

注: “cat_2” 是旧范畴。

我使用VPS服务器。

请帮忙!

+0

你找到任何解决办法? – vaibhav

+0

hello @vaibhav我找到了解决方案。 你可以使用如下的脚本: '进口CGI 的categorys = cgi.escape(的categorys,真) post.terms_names = { 'post_tag':的categorys, '类别':的categorys}' – Tarjo

+0

感谢@Tarjo ...我已经找到了解决方案,再次欢迎 – vaibhav

回答

0

'terms_names'将创建新的类别,如果你想使用现有的类别,使用'terms'并传递该类别的id。所以不是:

post.terms_names = { 'post_tag': categorys, 'category': categorys } 

应该

post.terms = { 'post_tag': 1, 'category': 2 } 

假设标签的ID为1和类别ID为2