好的,我已经使用" 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
注意:我知道如何上传多个文件,但我不了解如何在产品库中添加这些图片。
答案 0 :(得分: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()