How to display events within a given date range only?

Home Forums Calendar Products Events Calendar PRO How to display events within a given date range only?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #107971
    florianubr
    Participant

    Hi, I am using the Agenda template for a custom list-style view. What I want to achieve is display a list of all event occurring between two given dates; e.g. events that start between today and the next 7 days. I am currently using a custom query as described in one of your FAQs (https://theeventscalendar.com/queries-and-pagination/) to additionally filter the events by some other criteria. However, I don’t know how to ask for events starting after a date 1 but starting no later than before date 2.

    Also I would like to customize this query further, so I get results back grouped by events that recur or don’t; so I can easily display all non-recurring events of a date first, then all the ones recurring on the specific date.

    Is there any documentation available on which arguments I can use for Events Calendar Pro with WP_Query()?

    #108644
    Brook
    Participant

    Howdy florianubr,

    We do have some fairly good documentation on this function here. Even though it is technically outdated as it is for version 2.x of our plugin, the examples all tend to work on 3.x as well.

    Here is an example of code specifically to fit your needs.

    Does that documentation help? Please let me know. Cheers!

    – Brook

    #108927
    florianubr
    Participant

    Thanks for hinting me to these docs, Brook. Couldn’t find them by myself and they look very interesting. However, I am looking forward to solve my problem using WP_Query() instead of tribe_get_events() – mainly because I also need to add additional query elements for filtering search results with bindings to standard WP categories. Also support for paging would be good to have, for which your documentation describes to use WP_Query() –> https://theeventscalendar.com/queries-and-pagination/

    However, when I try to use WP_Query, out of some reason it seems, both arguments “end_date” as well as “start_date” seem to be ignored. The start date for events listing always seems to be the one set by tribe-bar-date. How can I make “start_date” and “end_date” work with WP_Query()?

    #109124
    Brook
    Participant

    Howdy florianubr,

    That is likely because end_date and start_date are not columns within the DB nor are they valid WP Query paramets, they are stored as post_meta. Those Query vars only work withing tribe_get_events() because it adds a lot of logic to understand them. There is actually a quite a bit of code that goes into using them and creating date range queries. But, if you are willing to spend a bunch of hours recreating that functionality the TribeEventsQuery class is a great place to start to see how it all works.

    Furthermore, if you would like to see the full query args and even the SQL that tribe_get_events() uses to create a query, set the $full argument of tribe_get_events to true: tribe_get_events(array(..), true). That additional info will likely prove very helpful if you are trying to recreate these queries.

    Does that make sense? Please let me know. Cheers!

    – Brook

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘How to display events within a given date range only?’ is closed to new replies.