WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have three sets of period of time, each with several interval of date:

Event A
Jan 1 - March 1
Dec 1 - Dec 31

Event B
Mar 2 - April 15
Jun 1 - Jul 15
Sept 1 - Oct 15

Event C
Apr 16 - May 31
Jul 16 - Aug 31
Oct 16 - Nov 30

I really would like to know how to show a custom field if today's date is fall between a certain period. Say today is April 22, then custom field to show is "Event C".

Really appreciate if someone can help me resolve this issue.

share|improve this question
Not really sure what you're trying to achieve here, but I think you have to create your own custom sql query and you can have date comparison in mysql pretty easily => date1 >= $myDate AND date2 <= $myDate. – Hamed Momeni Apr 22 '12 at 7:02

Here's a function you can put in functions.php.

function get_current_event() {
    global $post;
    $now = get_the_time('U');
    $year = get_the_time('Y');
    if($now >= strtotime("January 1 $year") && $now < strtotime("March 1 $year")) {
       return get_post_meta($post->ID,'eventA',true);
    if($now >= strtotime("March 1 $year") && $now < strtotime("October 15 $year")) {
        return get_post_meta($post->ID,'eventB',true);
    $nextyear = $year+1;
    if($now >= strtotime("October 15 $year") && $now < strtotime("January 1 $nextyear")) {
        return get_post_meta($post->ID,'eventC',true);
    return false;

Then you can put this in your template:

print get_current_event(); 
share|improve this answer

Your Answer


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.