pip install python_wordpress_xmlrpc
from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods import posts wp = Client(' https://domain.com/xmlrpc.php ', 'username', 'password') def post_new_article(title, content): post = WordPressPost() post.title = title post.content = content Post. post_status='draft' # Post status. If not written, it is draft by default. Private means private, draft means draft, and publish means release post.terms_names = { 'category': ['category directory'], 'post_tag': ['Tag1 ',' Tag2 '], } post.id = wp.call(posts. NewPost(post)) return post.id
# -*- coding: utf-8 -*- from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods import posts Username="Administrator User Name" Password="Administrator password" Apiurl="http://domain name/xmlrpc. php" # xmlrpc path of website wp = Client(apiurl, username, password,) print(wp) post = WordPressPost() Post. title='Article title 2' Post. content='Article content' Post. post_status='publish' # Post status. If it is not written, it is draft by default. Private means private, draft means draft, and publish means release post.terms_names = { 'post_tag': ['test ',' firstpost '], # The tag of the article. If there is no tag, it will be created automatically 'category': ['Introductions', 'Tests'] # The category of the article. If there is no category, it will be created automatically } post.id = wp.call(posts. NewPost(post)) print(post.id)