I have a lot of Custom Posts that I need to set featured images for, based on a custom taxonomy.
I am trying to see if there is a way to do this via wp-cli, I see an example offered there which would let me import and set an image to all posts of the CPT. However I cannot figure out if it is possible to further filter that by a custom taxonomy.

ATTACHMENT_ID="$(wp media import ~/Downloads/image.png --porcelain)"
wp post list --post_type=post --format=ids | xargs -0 -d ' ' -I % wp post meta add % _thumbnail_id $ATTACHMENT_ID

The command wp post list has an optional field for “filter”, is that useful, I cannot see what it does.

1 Answer
1

In WP-CLI list the arguments in WP_Query are defined by the associated arguments like --post_type=post. To be able to filter custom taxonomies you would need to use tax_query. Unfortunately WP-ClI does not support argument array so it is not possible.

It is on the other hand possible with the WP-CLI Rest package. You can install it by running wp package install wp-cli/restful.

You should be able to query it with the command wp rest post list

https://github.com/wp-cli/wp-cli/issues/3039

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *