[英]Python - python-wordpress-xmlrpc add tags to a post with known id
[英]Upload images gallery to wordpress with python-wordpress-xmlrpc
好的,我已经使用“python-wordpress-xmlrpc”包在python中创建了一个脚本,除了将多个图像上传到wordpress然后将它们添加到图库之外,我可以做任何事情。
这是我上传单个图像文件然后设置为特征图像的代码:
fileImg = urlopen('image_url')
imageName = fileImg.url.split('/')[-1]
imageType = mimetypes.guess_type(str(fileImg.url))[0]
data = {
'name': imageName,
'type': imageType,
}
data['bits'] = xmlrpc_client.Binary(fileImg.read())
response = client.call(media.UploadFile(data))
attachment_id = response['id']
widget.thumbnail = attachment_id
注意:我知道如何上传多个文件,但我不明白如何在产品库中添加这些图像。
这种技术对我有用:
attachment_id = response['id']
alt_value = "image alt"
sql = """INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES (%d,'_wp_attachment_image_alt','%s');""" % (int(attachment_id ), alt_value)
mycursor.execute(sql)
mydb.commit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.