• Resolved eccles42

    (@eccles42)


    Hi,

    On a website that I maintain I use the tribe_get_events function to retrieve an event for a given date (to create a link in a calendar to the event page). This was working fine for a while but at some point (i’m not sure when) it stopped working for multi-day events. It’s still fine for single day events, If I change a multiday event to start and end on the same day it shows up

    Here’s the code that I’m using…

    // Retrieve one event on date
    $events = tribe_get_events(  [
    	'eventDisplay' => 'custom',
    	'start_date'   => $searchDate.' 00:01',
    	'end_date'     => $searchDate.' 23:59',
    	'posts_per_page' => 1
    ] );

    As I understand it, this should return any active events between the two dates, and it was working fine for a while. I’ve tried lots of variations (with without dates), and have confirmed that it’s returning 0 results. Any suggestions?

    Andy

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi Andy,
    Thanks for writing in,

    From what I see in your snippet, there are a couple of things to point out.
    It will never retrieve multiday events, as it is specifically telling to bring events starting and ending within the same date ($searchDate).
    Also, it all depends on the value of $searchDate.This should be assigned with a date without time.
    Here is a knowledgebase article that will help you on this: https://support.theeventscalendar.com/666307-Using-tribe_get_events

    Please let me know if this helps
    Best
    Santiago

    Thread Starter eccles42

    (@eccles42)

    Thanks for the reply. The thing is that it used to work and worked for quite a while. I’d seen that page and my understanding of it was that start_date and end_date indicated the date range to search within, as described here – https://support.theeventscalendar.com/666307-Using-tribe_get_events/666307-Using-tribe_get_events?r=1#event-specific-arguments

    If start_date was the start of the events then the first example would only return events starting on the day passed to the function, not the next 5 events.

    Amway I just wondered if anyone had encountered something similar as I can always code around it.

    Thanks,

    Andy

    Hello, I need to do the same thing.
    And I search to do it.
    For exemple, I need to have all events on Novembre the 16th.
    And for multidays events, the events that have a start_date before and a end_date after, must be shown…

    Thread Starter eccles42

    (@eccles42)

    Here’s my workaround in case its of any use to anyone. This function returns url and title of events that occur on a specific day, I use it in a calendar.

    You’ll just need to adjust the “-3 days” to suit the length of events since tribe_get_events wont return events already in progress. It needs a bit more refinement, like an end date so it doesn’t keep returning a whole year, but hopefully it’ll help someone.

    function get_event_link($day,$month,$year)
    {
    	global $post;
    		
    	$searchDate = mktime(00, 00, 00, $month, $day, $year);
            
    	// Retrieve events from the search date -3 days
    	$events = tribe_get_events(  [
        	'eventDisplay' => 'custom',
        	'start_date'   => strtotime('-3 days',$searchDate)
    	] );
    	
    	//loop through the events until an event between the start end end date is found
    	foreach ( $events as $post ) {
        	setup_postdata( $post ); 
                $startDate = strtotime(tribe_get_start_date($post->ID, false, 'Y-m-d'));
                $endDate = strtotime(tribe_get_end_date($post->ID, false, 'Y-m-d'));
        
                if($searchDate>=$startDate && $searchDate<=$endDate)                    
    		return array(tribe_get_event_link($post),$post->post_title);
    	}
    }

    Andy

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘tribe_get_events and multiday events’ is closed to new replies.