用python-wordpress-xmlrpc上传图片库到wordpress。

问题描述 投票:2回答:1

好吧,我已经用python创建了一个脚本,使用 "python-wordpress-xmlrpc "包,我能够做所有的事情,除了上传多个图片到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

注:我知道如何上传多个文件,但我不明白如何将这些图片添加到产品图库中。

python wordpress xml-rpc
1个回答
0
投票

这个技术对我来说是可行的。

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()
© www.soinside.com 2019 - 2024. All rights reserved.