WP_Query events with date year filter

Home Forums Calendar Products Events Calendar PRO WP_Query events with date year filter

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #148389
    unikmedia
    Participant

    Hi,

    I’m trying to get all events from a specific year with a WP_Query. But it takes the year of the publish date. How can i get the event’s start date?

    $evenements = new WP_Query(array(
    ‘post_type’ => ‘tribe_events’,
    ‘posts_per_page’ => ‘-1’,
    ‘orderby’ => ‘menu_order’,
    ‘order’ => ‘ASC’,
    ‘post_status’ => array(‘publish’, ‘pending’, ‘draft’, ‘auto-draft’, ‘future’, ‘private’, ‘inherit’, ‘trash’),
    ‘tribe_events_cat’ => $category,
    ‘eventDisplay’ => ‘all’,
    ‘date_query’ => array(
    ‘year’ => $myYear
    )
    ));

    #150435
    Barry
    Member

    Hi!

    I’m going to move this thread out of the translations forum and over to the PRO forum – but the URL should remain the same 🙂

    Instead of the date query component, try using start_date and end_date arguments (with a format like 2014-10-01 12:00:00) … you may also need to switch the value of eventDisplay to custom.

    Does that help?

    #150518
    unikmedia
    Participant

    $evenements = new WP_Query(array(
    ‘post_type’ => ‘tribe_events’,
    ‘posts_per_page’ => ‘-1’,
    ‘orderby’ => ‘menu_order’,
    ‘order’ => ‘ASC’,
    ‘post_status’ => array(‘publish’, ‘pending’, ‘draft’, ‘auto-draft’, ‘future’, ‘private’, ‘inherit’, ‘trash’),
    ‘tribe_events_cat’ => $category,
    ‘eventDisplay’ => ‘all’,
    ‘start_date’ => $year . ‘-01-01 00:00:00’,
    ‘end_date’ => $year . ‘-12-31 23:59:59’
    ));

    Did the trick! Thank you

    #151615
    Barry
    Member

    Awesome (and thanks for sharing your final solution) 🙂

    I’ll go ahead and close this thread, but of course if we can assist with anything else please don’t hesitate to open a new thread or threads as needed.

    Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘WP_Query events with date year filter’ is closed to new replies.