📝 The meta_query That Assumed AND Without Asking
A meta_query array with two or more clauses needs an explicit relation key to say how those clauses should be combined, and leaving that key out doesn’t leave the behavior undefined – WP_Query quietly defaults to AND. A query meant to find listings that are either featured or sold, with no relation key ever set, silently becomes a search for listings that are both featured and sold at the same time, which on most sites is a rare or nonexistent combination, so the query just returns far fewer results than expected, or none.
🔎 The Problem
<?php
$query = new WP_Query( array(
'post_type' => 'listing',
'meta_query' => array(
array(
'key' => 'featured',
'value' => '1',
),
array(
'key' => 'status',
'value' => 'sold',
),
),
) );
// Intent (implicit, never stated): "featured listings OR sold
// listings." Actual: WP_Query defaults an unlabeled multi-clause
// meta_query to 'relation' => 'AND', so this silently returns
// only listings that are BOTH featured AND sold at once.
✅ Fix: Always Set relation Explicitly on Multi-Clause meta_query
- Add an explicit ‘relation’ => ‘OR’ (or ‘AND’, whichever is actually intended) as its own top-level entry inside meta_query any time there are two or more clauses – never rely on the default, and flag its absence in review for any meta_query with multiple clauses.
- When a meta_query’s result count looks suspiciously low, check for a missing relation key before assuming the underlying post meta itself is wrong – a query silently running as AND when OR was intended is a far more common cause of “too few results” than the stored data actually being incomplete.
- For anything beyond two simple clauses, nest meta_query arrays explicitly – an inner array with its own relation, combined with an outer relation – rather than relying on a flat list of clauses and an assumption about how they combine; a flat list’s combining rule becomes genuinely ambiguous to a future reader once there are three or more clauses.
⚠️ Why This Is Easy to Miss
- The query runs without any PHP warning or WordPress debug notice – an incorrect default relation produces a perfectly well-formed, successfully executing SQL query, it just isn’t the query anyone actually intended to write.
- A meta_query with exactly one clause behaves identically regardless of the relation key, since there’s nothing yet to combine – the bug only appears the moment a second clause is added later, often by a different developer with no reason to suspect the original single-clause query’s behavior is about to change.
meta_query doesn’t ask how you want two conditions combined – it assumes AND, silently, and the documentation has to be read specifically to find out that’s the default.

