【问题标题】:Upload images gallery to wordpress with python-wordpress-xmlrpc使用 python-wordpress-xmlrpc 将图片库上传到 wordpress
【发布时间】:2016-08-11 02:49:56
【问题描述】:

好的,我已经使用“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

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

【问题讨论】:

  • 嗨,你找到解决办法了吗?

标签: python wordpress xml-rpc


【解决方案1】:

这项技术对我有用:

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()

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 2011-01-28
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 2021-10-03
    • 1970-01-01
    相关资源
    最近更新 更多