My query works when the date argument is removed, it returns 10 rows.
When I add my AND line for comparing a date value I have stored in post meta too a PHP date with the same format. The query does not return any records.
My conclusion is that it is because meta values are strings and this may need a date to be stored in a MySQL date data type.
How do I get around this? Here is the query...
`SELECT wposts.* FROM wp_posts wposts, wp_postmeta metaprojectcode, wp_postmeta metaupdated
WHERE wposts.ID = metaprojectcode.post_id
AND wposts.ID = metaupdated.post_id
AND (metaprojectcode.meta_key = 'csv2post_project_code' AND metaprojectcode.meta_value = 'proh4hyq2')
AND (metaprojectcode.meta_key = 'csv2post_last_update' AND metaupdated.meta_key < '2012-11-04 23:41:31')
So you see I want to get posts that share one meta value and have a date value that is less than the example in the query. Should you be wondering, I do have a date of 2012-11-04 00:45:13 in meta which has the same post ID as a meta record with proh4hyq2.
I know a way to do this that would require possibly very long PHP loops and 2 queries. So an alternative would help greatly and advice be appreciated.