Milo told you the answer. You need to store your data as individual keeps in the database rather than as a serialized array. MySQL cannot natively parse a serialized array though I have seen very complicated SQL that will. Still, that code is not going to be useful on a production server. It is too complicated and would be too slow. So…
… is there any possibility with present case?
… if you mean “Can I make this work with the serialized data I have?” then “no”, not really. You have to change how the data is stored in the database. If you have already done that– perhaps that is what the edit means, I can’t quite tell– then what you need is a JOIN
.
SELECT
wp_posts.*
FROM wp_posts
LEFT JOIN wp_postmeta
ON wp_postmeta.post_id = wp_posts.ID
WHERE 1=1
AND wp_posts.post_type="shop_order"
AND post_date >= '2013-08-26'
AND post_date < '2013-10-28'
AND post_date_gmt NOT LIKE '0000%'
AND wp_postmeta.meta_key = 'whatever'
AND wp_postmeta.meta_value="somevalue"
ORDER BY wp_posts.post_date DESC
The logic and the SQL for joins can get complicated so you may need a lot more code than that.
And you should probably consider using WP_Query
with a meta_query
argument instead of your hand-rolled SQL.
At the very least use $wpdb->posts
and $wpdb->postmeta
instead of the hard-coded table names. What you’ve got is not portable.