I'm just meeting with wordpress_xmlrpc library for python . Awesome documentation, red it all for future, but still can't catch, how to mark post for 1-2 categories by ids. It seems to easy, but not for me. I can't make a post in category. When I'm trying to declare a category it posts in all categoryies, else only in category with id = 1.
wp = Client('http://example.com/wordpress/xmlrpc.php', 'admin', 'admin')
post = WordPressPost()
post.title = 'My post'
post.content = 'The best post ever.'
post.id = wp.call(posts.NewPost(post))
cats = wp.call(taxonomies.GetTerms('category', 2))
post.terms = cats
post.post_status = 'publish'
wp.call(posts.EditPost(post.id, post))
In this code example is category id 2
, also I declared it like (2)
and [2]
, tryed many categoryes (2, 4)
, [2, 4]
. No difference.
Ofcourse there are categories with such ids, no mistake there.
Ok, I sorted out. wp.call(taxonomies.GetTerms('category'))
as I tried firstly, get a list of avalible taxonomies objects. To mark post in some category:
category_id = 3
cat = wp.call(taxonomies.GetTerm('category', category_id))
post.terms.append(cat)
If is needed to mark the post in 2+ categories, best way is to append them separetaly from each other, because post.terms is a list.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.