5

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

3

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
1
  • Looks like this is no more working
    – FiftiN
    Mar 6, 2021 at 9:31
2

You may pass any standard WP_Query arguments as flags to the wp post list command.

--<field>=<value>

In your example you would use the meta query arguments.

wp post list --fields=ID,mycustomfield --meta_key=mycustomfield --meta_value=active

Vague documentation is here.

1
  • This is the one that works! Thank you.
    – robrecord
    Sep 6 at 11:10

Your Answer

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

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