WP-CLI – Return posts with matching meta key

I am using the WP-CLI to manage my sites. I can run the following command

wp post list --fields=ID,mycustomfield

 ID   |  mycustomfield
-----------------------
 1    |  active
 2    |  active
 3    |  disabled
 4    |  active

I am trying to narrow this list down by only returning those which has mycustomfield as active

Any ideas how I can do this?

2 Answers
2

Managed to figure this out, you can pass –meta_key and –meta_compare arguments like this…

wp post list --fields=ID,mycustomfield --meta_key=mycustomfield '--meta_compare=active'

ID   |  mycustomfield
-----------------------
 1    |  active
 2    |  active
 4    |  active

Leave a Comment