Why does this return all posts;
$partner = get_query_var('partner');
echo "Partner ID: ". $partner; // Echoes correctly
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
'meta_key' => 'partner',
'meta_value' => array($partner), // also $partner (without array)
'compare' => 'LIKE', // Also 'IN'
),
);
$partner_query = new WP_Query($args);
the ACF field ‘partner’ is an array, the query variable is a string (obv)
3
Answers
For anyone who gets stuck in this rabbit hole.
My query parameter is a string, ACF stores the IDs as a string if there's one and an array if there's more than one.
This form of the arguments returns the correct results. (many thanks to Howard E and IronCanTaco)
Try like this:
The correct usage of
meta_query
is like this:The args shouldn’t be
meta_key
if you’re using meta_query – they should bekey
,value
, etc.