Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to be able to display a custom post type if the current date is between the start and end custom meta field dates. Here is my code so far, it seems to just be ignoring the query and displaying all 3 of the posts, I have probably made a mistake as I have been been working on it for 3 days straight now, any help would be greatly appreciated. I am not even sure if this can work, I have successfully been able to show the posts that are after the end date and posts before the start date but can seem to get the ones that are between the two dates.

    $todaysDate = date('Y/m/d');
$args = array(
'post_type' => 'exhibitions',
'orderby' => 'meta_value',
'post_status' => 'publish',
'meta_query' => array(

    array('key' => 'start_date', 'value' => $todaysDate, 'compare' => '>=', 'type' => 'DATE'),
    array('key' => 'end_date', 'value' => $todaysDate, 'compare' => '<=', 'type' => 'DATE') 
) ); 
share|improve this question
add comment

1 Answer

Untested solution, just a thought really, but what if 'value' => 'NOW()' so that you avoid having to pass the date, which seems like it's probably the issue?

EDIT

Alternate solution: Your SQL date format is wrong. It should be $todaysDate = date( 'Y-m-d' ), that should also be the format it is stored in if the row format is DATE or TIME

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.