How to display upcoming events by dat with Modern Events Calendar Lite
I'm using the plugin Modern Events Calendar Lite.
This is a recent plugin, so actually no doc exist.
So i'm looking a way to display my upcoming events on homepage. But i can not make it to work, because start is stored in a second table.
So i have a wpquery that list custom posts "mec-events", this is ok. But i'm not able to JOIN info to second table to get start_date to order posts on its value.
I add you a capture of the second table wp-mec-dates events are store in wp-mec-events
Based on this tuto : Filtering the JOIN tables in WP_Query exemple code :
add_filter( 'posts_join', 'add_other_table', 10, 2 );
/**
* Joining another table and relating the column post_id with the Post's ID
*
* @param string $join String containing joins.
* @param WP_Query $wp_query Object.
* @return string
*/
function add_other_table( $join, $wp_query ) {
global $wpdb;
$join .= " JOIN {$wpdb-prefix}my_table as mytable on mytable.post_id = {$wpdb-posts}.ID ";
return $join;
}
i figure to do like this :
?php
$args = array(
'post_type'= 'mec-events',
'orderby' = 'dstart',
'order' = 'ASC',
);
add_filter( 'posts_join', 'add_other_table', 10, 2 );
function add_other_table( $join, $upcoming_events_query ) {
global $wpdb;
$join .= " JOIN {$wpdb-prefix}mec_dates as wp_mec_dates on wp_mec_dates.post_id = {$wpdb-posts}.ID ";
return $join;
}
$upcoming_events_query = new WP_Query( $args );
if($upcoming_events_query-have_posts() ) {
while ( $upcoming_events_query-have_posts() ) {
$upcoming_events_query-the_post();
$image_url = get_the_post_thumbnail_url('','liste-etablissements');
$event_cities = get_field('contact_city',$post-ID);
$start_date = get_field('dstart');
var_dump($start_date);
?
div class="presta-img-home-events"
?php if($image_url[0]) { ?
img src="?php echo esc_url( $image_url ); ?" alt="?php the_title_attribute(); ?"
?php } else { ?
img src="?php echo get_template_directory_uri() . '/images/placeholder-blog.jpg'; ?" alt="?php the_title_attribute(); ?"
?php } ?
div class="presta-img-home-events-overlay"?php //echo $start_date; ? - ?php if($event_cities) { $cities = 0; $max_cities = 1; foreach($event_cities as $event_city) { $cities++; if($cities $max_cities) { break; } echo ''. get_the_title( $event_city-ID ) .''; } } ?/div
/div
div class="featured-content-wrapper"
h3 class="featured-title" a title="?php the_title_attribute(); ?" href="?php the_permalink(); ?"?php the_title(); ?/a/h3
!--a href="?php the_permalink(); ?" class="single_add_to_wishlist" ?php esc_html_e('Découvrir','BeProvence'); ?i class="fa fa-heart"/i/a--
/div!-- featured content wrapper --
?php
}
}
?
But my var_dump() return "null". So i probably do something wrong. Any help will be apreciate !