• Resolved jlongbrake

    (@jlongbrake)


    I have a custom script that creates events using data from a form submission. That is all working great, but I am working on adding some script to check if someone may be double booking a room during a certain time and just alert the user to manually check for the conflict. I’ve used ‘tribe_get_events’ to get the events within the timeframe of the event being added and have gotten it to only look in the same category being added as well. The problem I’m having is that if an event starts during the one I’m trying to add, but ends after the end_date it does not include that event in the list of events, but since the times are overlapping I need it to show as a potential conflict. How can I get it to include events that start within the given timeframe, even if they end outside of the timeframe?

    Here is an example of my code: tribe_get_events([‘start_date’ => $start_date->format(‘Y-m-d H:i’), ‘end_date’ => $end_date->format(‘Y-m-d H:i’), ‘tax_query’=> array( array( ‘taxonomy’ => ‘tribe_events_cat’, ‘field’ => ‘slug’, ‘terms’ => $room ) )]);

    Example: I’m adding an event on June 9th from 1pm to 4pm. There is already an event in that category on June 9th from 3:30pm to 5:30pm. I need to get the event starting at 3:30pm so I can alert the user of a potential conflict.

Viewing 1 replies (of 1 total)
  • Thread Starter jlongbrake

    (@jlongbrake)

    I’ve figured out a solution to this using a regular WordPress query. I found and modified some code from a plugin that does this for venues. Here is what I ended up with if it happens to help anyone in the future:

    global $wpdb;
    
    $args = array(
    	'post_type' => 'tribe_events',
    	'meta_query' => array(
    		'relation' => 'AND',
    		array(
    			'key' => '_EventStartDate',
    			'value' => $end_date->format('Y-m-d H:i'),
    			'compare' => '<'
    		),
    		array(
    			'key' => '_EventEndDate',
    			'value' => $start_date->format('Y-m-d H:i'),
    			'compare' => '>'
    		)
    	),
    	'tax_query' => array(
    		array(
    			'taxonomy'	=> 'tribe_events_cat',
    			'field'		=> 'slug',
    			'terms'		=> $room
    		)
    	)
    );
    			
    $events_on_date = get_posts($args);
    • This reply was modified 3 years, 4 months ago by jlongbrake.
Viewing 1 replies (of 1 total)
  • The topic ‘Help selecting specific dates with tribe_get_events’ is closed to new replies.