API website connection

Home Forums Calendar Products Events Calendar PRO API website connection

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1350996
    spottedinely
    Participant

    Is there a way of using api to snapshot some data from one website to another for the calendar.

    An example, we 2 websites, both for the same project and one has calendar on it and I would like the second website to show the same next 7 days list that appears on the first

    Mark

    #1351856
    Barry
    Member

    Hi Mark,

    That certainly sounds like a viable customization 🙂

    On that note, I do need to mention right off the bat that the amount of support we can offer for custom development tasks tends to be limited, but I’d be only too pleased to see if I can point you in the right direction.

    Here’s a code sample outlining interaction with the REST API on a remote site (in my example, our demo site) that contains an active and up-to-date copy of The Events Calendar:

    $now = date_create()->format( 'Y-m-d' );
    $end = date_create()->modify( '+7 days' )->format( 'Y-m-d' );
    
    $url = 'http://wpshindig.com/wp-json/tribe/events/v1/events';
    $url = add_query_arg( 'start_date', $now, $url );
    $url = add_query_arg( 'end_date', $end, $url );
    
    $data = null;
    $events = array();
    $response = wp_remote_get( $url );
    
    if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) {
    	$data = json_decode( $response['body'] );
    }
    
    if ( ! empty( $data->events ) && is_array( $data->events ) ) {
    	$events = $data->events;
    }
    
    foreach ( $events as $source_event ) {
    	print_r( $source_event );
    }

    In essence, it requests the upcoming week’s worth of events and if it successfully obtains them it loops through them (you could then format them nicely and display them, whereas for demonstration purposes I simply ‘dump’ the data to the screen).

    It would need a lot more polish – you’d probably want to cache the result of the lookup, for example, or store it somewhere like your own database (and/or you could commit the data to your local copy of The Events Calendar) – but it should at least give you the basic idea.

    I hope that helps!

    #1362692
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘API website connection’ is closed to new replies.