1

I want to list out posts by querying multiple meta data's in order to pipe them into an xarg wp post delete --force --defer-term-counting Eg.

$meta_query = array(
    'relation' => 'AND',
    array(
        'meta_key' => 'first_key',
        'meta_value' => 'first_value',
    ),
    array(
        'meta_key' => 'second_key',
        'meta_value' => 'second_value',
    ),
);

But all I have found in the documentation and in my googling's is how to use a single meta:

wp post list --fields=ID,first_key --meta_key=first_key --meta_value=first_value

The strange thing is that I haven't found anyone else asking this, so I haven't found a negative answer saying it isn't possible either.

1 Answers1

2

give the following below a try. Here is a summary from the WP Codex documentation: https://developer.wordpress.org/reference/classes/wp_query/

meta_key (string) – Custom field key.
meta_value (string) – Custom field value.
meta_value_num (number) – Custom field value.
meta_compare (string) – Operator to test the ‘meta_value‘. Possible values are ‘=’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘<=’, ‘LIKE’, ‘NOT LIKE’, ‘IN’, ‘NOT IN’, ‘BETWEEN’, ‘NOT BETWEEN’, ‘NOT EXISTS’, ‘REGEXP’, ‘NOT REGEXP’ or ‘RLIKE’. Default value is ‘=’.
meta_query (array) – Custom field parameters (available since version 3.1).
relation (string) – The logical relationship between each inner meta_query array when there is more than one. Possible values are ‘AND’, ‘OR’. Do not use with a single inner meta_query array.

Hope that helps in some way!

wp post list --fields=ID,first_key --meta_key=first_key --meta_value=first_value --relation='AND' --meta_key=second_key --meta_value=second_value