1

I've been searching for a good few days now trying to get my WordPress event calendar by modern tribe working as I need it to.

I have hundreds of order by and delivery dates in DB each one separated by about 5-10 weeks. what I'm trying to achieve is a list where I can see the all the events starting on today's or yesterday's date.

This sounds simple however the problem appears to be when you query events between two dates it will query both the start and end date giving you historical events which don't need to be seen and can be confusing.

I believe the way to overcome this is with a wp_query and meta_query but no matter which way I try to add the meta query to sort by start date only it breaks the whole thing.

this is the query below any help would be awsome as I've little hair left to pull out!

 <?php
  $query = new WP_Query( array( 'post_type' => 'tribe_events',
    'meta_query' => array(
        array(
            'key' => '_EventStartDate',
            'value' => date('Y-m-d H:i:s', strtotime('-1 week')),
            'compare' => 'date'
        )
    )
  ) );
  if ($query->have_posts())
  {
    while ($query->have_posts()) : $query->the_post();
        echo $query->post->EventStartDate . ' ';
        echo $query->post->post_title . '</br>';

    endwhile;
  }
  wp_reset_query();
  ?>

I've also tried changing the meta value to

  'value' => date('Y-m-d', strtotime('-1 week')),

but this didnt work either...

Thanks

2

What I would do is create a query for the _EventStartDate with a custom 'eventDisplay'. This will grab all events, ordered by the start date. Then, once you get into the loop; compare the start date to a specific date that you want to output. tribe_get_start_date() accepts a date format parameter (see here) that will allow you to return the format that you would like to compare against. Note, This code is untested but should put you on the right track.

$args = array(
    'post_status'=>'publish',
    'post_type'=> 'tribe_events',
    'posts_per_page'=> 10,
    'meta_key'=> '_EventStartDate',
    'orderby'=> '_EventStartDate',
    'order'=> 'DESC',
    'eventDisplay'=> 'custom',
);

$query = new WP_Query($args);

if ($query->have_posts()) {
    while ($query->have_posts()) : $query->the_post();
        if(tribe_get_start_date() != [INSERT DATE TO COMPARE WITH]) {
            echo tribe_get_start_date() . ' ';
            the_title() . '</br>';
        }
    endwhile;
}

wp_reset_postdata();
  • I've tried your suggestions but unfortunately the query seems to ignore " if(tribe_get_start_date() != date('Y-m-d', strtotime('-1 week'))) {" and therefore returns all of the dates which is annoying. if youve any more suggestions im all ears... thanks again for your input – blackhill24 Dec 22 '16 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.