Displaying number of events in a day

Home Forums Calendar Products Events Calendar PRO Displaying number of events in a day

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #905506
    Butch Roy
    Participant

    I would like to create a custom template tag that counts how many events are in a given day. I’ve started with this:
    http://pastebin.com/zp7p5LVz

    However, that counts all the events, even when in a while loop. How can I have it only look for the number of events during a specific day? Is this something I need to include in the function, or do I have to put the function in some sort of loop?

    #905787
    Barry
    Member

    Hi!

    How about something like this:

    $events = tribe_get_events( array(
    	'eventDisplay' => 'custom',
    	'start_date'   => '2014-12-23 00:00:01',
    	'end_date'     => '2014-12-23 23:59:59'
    ) );
    
    print( count( $events ) );

    You would probably want to wrap this up in a function and make it more reusable by accepting a date parameter – but it should give the general idea 🙂

    #906307
    Butch Roy
    Participant

    An excellent start, thank you. So if I set up my function like this:
    http://pastebin.com/827mg9aa
    How can I pass it the current day in a while loop (specifically for a Week view)?

    #906511
    Barry
    Member

    You’re really asking something that’s more of a general PHP/coding question than something that’s specific to our plugin – but you could basically use an approach like this:

    for ( $day = 0; $day < 7; $day++ ) {
    	$date = date( 'Y-m-d', strtotime( "+$day days" ) );
    	huge_calendar_event_count( $date );
    }

    I’m using a for loop rather than a while loop, because it feels like a more natural fit, but you’re free to use whichever structure you prefer 🙂

    I hope that helps – and good luck!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Displaying number of events in a day’ is closed to new replies.