3

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.

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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