Search multiple meta keys at once

You’ll want to use the ‘meta_query’ argument of WP_Query ( http://codex.wordpress.org/Class_Reference/WP_Query )

Here’s a snippet that uses two separate meta key comparisons:

$query_args = array(
    'post_type' => 'event',
    'order' => 'ASC',
    'orderby' => 'meta_value_num',
    'meta_key' => '_start_date',
    'meta_query' => array (
                                    array(
                                        'key' => '_start_date',
                                        'value' => $_start_of_month,
                                        'compare' => '>',
                                    ),
                                    array(
                                        'key' => '_start_date',
                                        'value' => $_end_of_month, 
                                        'compare' => '<',
                                    ),
    ),

);

Important: Note that meta_query takes an array of arrays.

Leave a Comment