Adding custom routes to TEC REST API

Home Forums Calendar Products Events Calendar PRO Adding custom routes to TEC REST API

  • This topic has 0 replies, 2 voices, and was last updated 6 years ago by ccisatnu.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1485297
    ccisatnu
    Participant

    On my instance of The Events Calendar, I have added a custom field called “Campus” and created several event categories.

    I’d like to create separate feeds of events based on particular campuses and categories for a website I’m building. The website will have pages for each of our campuses and I’d like to pull in events categorized as “align” automatically to those pages. I’ve read Modern Tribe’s blog posts about REST API support and figured using the REST API would be the best solution.

    From what understand, I need to create a custom route that would produce feeds of events using the campus and category parameters.

    I think would be something like: http://mysite.com/wp-json/tribe/events/v1/events/?category=align&campus=Boston

    I have a two-part question:

    1. Is this the correct technique to use in this situation, or am I making it too complicated?

    If the answer to #1 is Yes…

    2. Do you have any recommended resources that would help me create this custom route? I’ve found a lot of tutorials on creating a custom route based on a single parameter, but I’m unable to find information on creating a route with multiple parameters.

    #1494280
    Barry
    Member

    Hi there @ccisatnu,

    Apologies first of all for the delay in responding. Unfortunately, this slipped through the cracks.

    I realize it’s been a while so possibly you have already resolved this … I also need to highlight that very technical customization questions such as this one are any case somewhat beyond the scope of support we can generally provide.

    That said, it does come to mind though that you can alter the queries used to fetch the data returned by the REST API pretty easily:

    function modify_rest_request_query( $query ) {
    	remove_action( 'tribe_events_pre_get_posts', 'modify_rest_request_query' );
    	// @todo modify event query according to meet your needs
    }
    
    function listen_for_rest_request( $pass ) {
    	add_action( 'tribe_events_pre_get_posts', 'modify_rest_request_query' );
    	return $pass;
    }
    
    add_filter( 'rest_dispatch_request', 'listen_for_rest_request' );
    

    So, if the REST API is what you want to use, that’s one avenue you could follow. If along the way you identify opportunities for us to make this sort of customization easier, perhaps by adding additional hooks to our own REST API code, do let us know 🙂

    #1514875
    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 ‘Adding custom routes to TEC REST API’ is closed to new replies.