Loop the next 5 events?
-
I just want to loop the next 5 events in my homepage, the title or thumbnail. There’s a simple way to do this with this plugin? I couldn’t find any example in the wiki and my knowledge of PHP is kinda poor.
Viewing 3 replies - 1 through 3 (of 3 total)
-
That’s a great question, time indeed that I update the documentation!
I just added another example in the wiki (see the 3rd example on that page):
https://github.com/ms-studio/minimalistic-event-manager/wiki/How-to-query-for-events
Here is the code for that query:
<?php // We define the current date, using the included function. $mem_today = mem_date_of_today(); // We set a limit for past events: $mem_date_expiration = ( 2 * DAY_IN_SECONDS ); // Here we will display them up to 2 days after they occurred. // Change that number according to your requirements. $mem_unix_limit = ( $mem_today["unix"] - $mem_date_expiration ); $mem_age_limit = date_i18n( "Y-m-d", $mem_unix_limit); // Now, the custom query: $args = array( 'posts_per_page' => 5, 'meta_key' => '_mem_start_date', 'meta_value' => $mem_age_limit, 'meta_compare' => '>=', 'orderby' => 'meta_value', 'order' => 'ASC', 'ignore_sticky_posts' => true ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : ?> <h1>Current Events</h1> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <h2 <?php post_class() ?> > <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </h2> <?php // Display the date, using the ready-made function. $mem_event_date = mem_date_processing( get_post_meta(get_the_ID(), '_mem_start_date', true) , get_post_meta(get_the_ID(), '_mem_end_date', true) ); ?> <span class="post-date"> Date: <?php echo $mem_event_date["date-num"]; ?> </span> <div class="post-excerpt"> <?php the_excerpt(); ?> </div> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php else : ?> <p><?php _e( 'No upcoming events.' ); ?></p> <?php endif; ?>Let me know if something is not clear.
Everything is super clear!!!
Thank you so much for your quick response, It works perfectly
Thanks for the feedback.
Always good to know that my code is understandable by others 🙂
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Loop the next 5 events?’ is closed to new replies.