I'm trying to set up a frontpage with multiple loops, the loops will be checking multiple custom fields in a custom post_type.
The post_type's name is products and the custom fields that have been attached to it are product_featured, product_start_date and product_end_date. The product_start_date and product_end_date date format is d-m-Y, so it is 01-09-2011.
Now I've tried to use WP_Query in combination with meta_query but noticed that it doesn't seem to work very well with arrays.
$args=array(
'post_type' => 'products',
'meta_query' =>array(
array( 'key' => 'product_start_date', 'value' => $date, 'type' => 'DATE', 'compare' => '=<' ),
array( 'key' => 'product_end_date', 'value' => $date, 'type' => 'DATE', 'compare' => '>=' ),
array( 'key' => 'product_featured', 'value' => 1 )
),
'post_status' => 'publish'
);
I have tried this with and without 'relation' => 'AND'. I've also tried it with both WP_Query and query_posts. Only the first loop will show results.
Now I'm trying to set it up with custom select queries, getting results in multiple loops and now I've bumped into another problem. I can't seem to figure out how to check the meta value against the current date.
This is what I'm currently using the custom query:
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND ( wpostmeta.meta_key = 'product_featured' AND wpostmeta.meta_value = '1' )
AND wposts.post_type = 'products'
AND wposts.post_status = 'publish'
ORDER BY wpostmeta.meta_value DESC
";
I've tried to add
AND ( wpostmeta.meta_key = 'product_start_date' AND STR_TO_DATE(wpostmeta.meta_value, '%d-%m-%Y') < '".date('d-m-Y')." ) )
and
AND ( wpostmeta.meta_key = 'product_start_date' AND STR_TO_DATE(wpostmeta.meta_value, '%d-%m-%Y') > '".date('d-m-Y')." ) )
...but no results.
What am I doing wrong? -_-