Title: Getting started with the ORM API
Last modified: February 14, 2023

---

# Getting started with the ORM API

 *  Resolved [jerrystewart99](https://wordpress.org/support/users/jerrystewart99/)
 * (@jerrystewart99)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/getting-started-with-the-orm-api/)
 * Hi,
 * I’m trying to programmatically get a list of events between two dates. Actually
   between ‘now’ and two days time.
   After trying the sql route (which ended in tears,
   lost within with the tec custom tables logic), I thought I’d try and do it properly
   and after discovering the ORM API documentation I got quite excited. [https://
   docs.theeventscalendar.com/apis/orm/]
 * The documents give some examples but not a complete list of keywords, syntax 
   etc.
 * I was expecting to find an and() function to combine logical expressions together.
   There is no such function.
 * The best I’ve come up with so far is
 * $events = tribe_events()
   ->where(‘start_date’, ‘>=’, ‘2023-02-14’)->where(‘start_date’,‘
   <=’, ‘2023-02-16’) ->pluck( ‘ID’ );
 * Whatever combination of dates I use, I get 150 results which is clearly incorrect.
 * Can anyone help get me going, or point me to some more extensive documentation
 * Thanks in advance, Jerry
    -  This topic was modified 3 years, 3 months ago by [jerrystewart99](https://wordpress.org/support/users/jerrystewart99/).

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

 *  Thread Starter [jerrystewart99](https://wordpress.org/support/users/jerrystewart99/)
 * (@jerrystewart99)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/getting-started-with-the-orm-api/#post-16472353)
 * Follow up: So, I’ve solved my initial problem but my question remains.. Where
   is the API defined?
 * I’ve created a statement that seems to work by a mixture of looking at the examples
   given in the docs and a bit of trial and error.. as follows:
 * $results = tribe_events()->where( ‘starts_after’, ‘now’ )
   ->where( ‘starts_before’,‘
   +2 days’ )->order_by( ‘event_date’ )->order( ‘ASC’ )->all();
 * <rant>
 * I guessed at the keyword ‘starts_before’. It seemed logical as there was a ‘starts_after’
   in the documented example. Are there other useful keywords? where are they defined?
   I also guessed ‘now’ as it seemed logical.
 * Why doesn’t where(‘end_date’, ‘<=’, ‘2023-02-16’) work?
 * Why is it order_by( ‘event_date’ ) instead of order_by( ‘start_date’ ) which 
   would seem more logical as start_date is a field in the returned ‘Event Object’
   but event_date isn’t.
 * When you chain where() clauses, it seems to default to a logical AND operation.
   What if you wanted a logical OR operation?
 * So many questions! I’d really love to understand this API more as it is truly
   elegant and nice to use.
 * </rant>
 *  Plugin Support [Darian](https://wordpress.org/support/users/d0153/)
 * (@d0153)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/getting-started-with-the-orm-api/#post-16495129)
 * Hi [@jerrystewart99](https://wordpress.org/support/users/jerrystewart99/)
 * Thanks for reaching out. I apologize for the late reply.
 * > I guessed at the keyword ‘starts_before’. It seemed logical as there was a ‘
   > starts_after’ in the documented example. Are there other useful keywords? where
   > are they defined? I also guessed ‘now’ as it seemed logical.
 * You could try the following keywords found in `the-events-calendar/src/Tribe/
   Repositories/Event.php` line [147](https://share.getcloudapp.com/7KuzekzN).
 * > Why doesn’t where(‘end_date’, ‘<=’, ‘2023-02-16’) work?
 * You could try `where('ends_on_or_before','2023-02-16')`
 * For your other questions, let me check with the team and I’ll get back to you
   on this once I have new information.
 *  Plugin Support [Darian](https://wordpress.org/support/users/d0153/)
 * (@d0153)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/getting-started-with-the-orm-api/#post-16541388)
 * Hi [@jerrystewart99](https://wordpress.org/support/users/jerrystewart99/)
 * Thanks for patiently waiting.
 * The base repository where function is defined here: [https://github.com/the-events-calendar/tribe-common/blob/master/src/Tribe/Repository.php#L518](https://github.com/the-events-calendar/tribe-common/blob/master/src/Tribe/Repository.php#L518)
 * Let me know if you have further questions or concerns.
 *  Thread Starter [jerrystewart99](https://wordpress.org/support/users/jerrystewart99/)
 * (@jerrystewart99)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/getting-started-with-the-orm-api/#post-16545645)
 * Hi [@d0153](https://wordpress.org/support/users/d0153/) Darian,
 * That’s great, thanks. I can definitely work with that.
    - Jerry

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

The topic ‘Getting started with the ORM API’ is closed to new replies.

 * ![](https://ps.w.org/the-events-calendar/assets/icon-256x256.gif?rev=2516440)
 * [The Events Calendar](https://wordpress.org/plugins/the-events-calendar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/the-events-calendar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/the-events-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/the-events-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/the-events-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/the-events-calendar/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)

 * 4 replies
 * 2 participants
 * Last reply from: [jerrystewart99](https://wordpress.org/support/users/jerrystewart99/)
 * Last activity: [3 years, 3 months ago](https://wordpress.org/support/topic/getting-started-with-the-orm-api/#post-16545645)
 * Status: resolved