Wp_query with 2 meta keys and array of meta values

Hi in my post_type=shop i have 2 meta keys and array of values

Custom fields

Read More
 Name           Values

 cu_status   pending,processing,completed

 cu_date     12-Jan-2016 , 13-Jan-2016, ......  any date in the same format date("d-M-Y")

Now i need to loop through all posts with cu_status =pending,processing and cu_date is between 12-Jan-2016 to 13-Apr-2016
What will the query ?

Iam very confused . For to get all post with status pending,processing I know the query

 $args = array(

        'post_type'         => 'shop',

        'post_status'       => 'publish',
        'meta_query' => array(
       array(
           'key' => 'cu_status',
           'value' => array('pending','processing'),
           'compare' => 'IN',
           )
           ),
           'posts_per_page' => -1
                );

Pleases help to complete the query .

Related posts

1 comment

  1. You need to use the relation operator e.g.

          $args = array(
            'post_type'         => 'shop',
            'post_status'       => 'publish',
            'meta_query' => array(
                'relation' => 'AND',
                array(
                    'key' => 'cu_status',
                    'value' => array('pending','processing'),
                    'compare' => 'IN',
                    ) , 
                array(
                    'key' => 'cu_date',
                    'value' => array($start, $end),
                    'compare' => 'BETWEEN',
                    'type' => 'DATE'
                    )   
                ),
            'posts_per_page' => -1
            );
    
    

    Also use the compare=>BETWEEN for getting the difference in 2 dates.
    You may need to tweak the code a bit as I have not tested it.

Comments are closed.