0

I am trying to bulk update media file captions through WP CLI so i can attribute image creators.

My command is as follows:

wp media list --date="2022-02-24" --format=ids | xargs -n 1 wp media meta update {} _wp_attachment_image_alt "<a href='https://www.freepik.com/'>Image by pch.vector on Freepik</a>"

I get these errors:

Error: 'list' is not a registered subcommand of 'media'. See 'wp help media' for available subcommands. Error: 'meta' is not a registered subcommand of 'media'. See 'wp help media' for available subcommands

I have the latest version, 2.7.1

On the WP CLI documentation, it lists media subcommands. There doesn't seem to be any subcommands for updating media meta.

https://developer.wordpress.org/cli/commands/media/

Does this mean there isnt a capability of updating media meta through wp cli?

1 Answer 1

3

Media is the post type (post_type="attachment"), so most operations are done with wp post command.

By default, wp post manage blog posts (post_type="post"), therefore by fetching post IDs you must add --post_type=attachment indicating the type of posts.
And to update media meta you should use wp post meta update <id> <key> <value>

Your entire command could look like this:

wp post list --date="2022-02-24" --format=ids --post_type=attachment | xargs -n 1 -I % wp post meta update % _wp_attachment_image_alt "{some meta value}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.