Publish a post using XML-RPC WordPress API and Python with category -


i'm doing migration website 1 use wordpress.

i created new custom types needs (with plugin custom post types), , created categories each custom type.

i wrote down script in python (adapted this article), gets posts db , pushes them remotely on new (testing) website, using new wordpress xml-rpc api supported since version 3.4.x.

at moment can publish new post correct post type. if specify category, wordpress returns me error:

xmlrpclib.fault: <fault 401: 'sorry, 1 of given taxonomies not supported post type.'> 

i'm sure post type supported given taxonomy. think i'm using wrong syntax specify category id. here's code:

import datetime, xmlrpclib, mysqldb  def post_remotely(post_data):      wp_url = "[my wordpress blog url]"     wp_username = "[myuser]"     wp_password = "[mypasswd]"     wp_blogid = "0"      status = 'publish'      server = xmlrpclib.serverproxy(wp_url)      data = { 'post_title': post_data['title'], 'post_content': post_data['content'],               'post_date': post_data['data'], 'post_type': post_data['post_type'], 'terms': post_data['categories'],               'post_status': status  }      post_id = server.wp.newpost(wp_blogid, wp_username, wp_password, data)      return post_id 

and on caller, specify category:

new_post['categories'] = [ { 'term_id': 3, 'taxonomy': 'news-cat' } ] 

"news-cat" name of taxonomy associated custom type "news". "term-id" id of category, found out using phpmyadmin.

i've tried other approaches no avail. without category works nicely.

thanks in advance :)

xml-rpc wordpress api document says:

struct terms: taxonomy names keys, array of term ids values. struct terms_names: taxonomy names keys, array of term names values. 

this means terms , terms_names directory, key name name of taxonomy want, , value array list.

if want set category, should set

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

or

‘terms_names’:{‘my-category’:["wordpress"]}  

in post structure, "my-category" name of taxonomy.

some information from:解决python发布wordpress内容返回抱歉,文章类型不支持您的分类法.错误


Comments

Post a Comment

Popular posts from this blog

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -