【发布时间】:2017-03-30 17:25:16
【问题描述】:
最近进入 python 中的 XML-RPC 库,我需要获取我的 wordpress 网站中所有帖子的 ID。我尝试使用EditPost() 命令,但似乎需要帖子的 ID。
在下面的代码中,我试图将所有帖子更改为草稿
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc import WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
from wordpress_xmlrpc.methods.posts import EditPost
wp = Client('website-link', 'x', 'x')
post = WordPressPost()
#Posts returns the name of the posts not IDs
posts = wp.call(posts.GetPosts())
print(posts)
for post in posts:
post.post_status = 'draft'
wp.call(EditPost(post,post))
print('done')
【问题讨论】:
-
我不知道 XML-RPC,但 doc 说它返回
string post_id。