I'm wanting to expand on the following query to look at multiple meta_key and meta_value values that have been created with the Advanced Custom Fields (ACF) plugin.


meta_key 'colours_%_colour' meta_value 'Red'


meta_key 'colours_%_design_style' meta_value 'Plain'

This is what I have so far which I came across on the ACF Documentation (https://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/)

It successfully retrieves results with the color (sub field) of red.

$rows = $wpdb->get_results($wpdb->prepare(

FROM {$wpdb->prefix}postmeta
WHERE meta_key LIKE %s
    AND meta_value REGEXP %s
'colours_%_colour', // meta_name
'red' // meta_value




1 Answer 1


is this what you're after? Using the "Relation" for the Meta Query, you can select multiple Meta Keys. You can change the "Compare" to any of the operations available for that function. (From the Codex) compare (string) - Operator to test. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS' and 'NOT EXISTS'. Default value is '='.

// WP_Query arguments
    $args = array (
            'post_type'          => 'your-post-type',
                'meta_query'          => array(
                'relation' => 'AND', 
                 'key'       => 'colours_%_colour',
                 'value'     => 'Red',
                 'compare'   => 'LIKE',

                 'key' => 'colours_%_design_style',
                 'value' => 'Plain',
                 'compare' => 'Like'

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        // do something
} else {
    // no posts found

// Restore original Post Data

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.