I’ve following query –
$query = array(
'post_type' => 'accessory',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'accessory-bike',
'value' => array("33"),
'compare' => 'IN'
)
)
);
And now I’ve this record in database –
520 is the ID for accessory
post type. It still returns 0 results. I can’t figure where the hell did I do wrong ? Stupid wordpress.
SELECT wp_posts.*
FROM wp_posts
INNER JOIN wp_postmeta
ON ( wp_posts.ID = wp_postmeta.post_id )
WHERE 1=1
AND wp_posts.post_type = 'accessory'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private')
AND ( ( wp_postmeta.meta_key = 'accessory-bike' AND CAST(wp_postmeta.meta_value AS SIGNED) IN ('33') ) )
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC
The value of
accessory-bike
on post 520 isn’t 33; it’s a serialized string.I can see you’re using Advanced Custom Fields so all you need to do is pick a different field type that doesn’t save data in a serialized string. You may find that something like a custom taxonomy is more appropriate.