6

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

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.
    – trebor
    Sep 6, 2023 at 11:10
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
2
  • Looks like this is no more working
    – FiftiN
    Mar 6, 2021 at 9:31
  • should be meta_value not meta_compare
    – trebor
    Mar 25 at 14:08

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.