Reputation: 3064
The below isn't working, can't see why. is_focus_product
is a True/False ACF field
$ls = get_posts([
'meta_query' => [
[
'key' => 'is_focus_product', 'value' => 1, 'compare' => '='
]
]
]);
// array(0){}
However this returns as expected...
var_dump(get_field('is_focus_product', 36));
// bool(true)
Upvotes: 0
Views: 2496
Reputation: 46
This is how I use query to get posts:
$args = array(
'post_type'=> 'products',
'posts_per_page' => 4,
'meta_key' => 'focus_product',
'meta_value' => 1
);
Upvotes: 0
Reputation: 3064
I found a solution but IMO it's a bullshit WordPress flaw, it shouldn't be restricted to a certain post type because you should have the freedom (in this case anyway, I reckon there are billions of similar use cases) to filter as necessary (they are ALL posts after all...).
You need the post type, so...
$ls = get_posts([
'post_type' => 'products',
'meta_query' => [
[
'key' => 'focus_product', 'value' => '1', 'compare' => '='
]
]
]);
Upvotes: 1