Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active May 10, 2018 19:27
Show Gist options
  • Save joshfeck/e3c9540cd4ccc734e755 to your computer and use it in GitHub Desktop.
Save joshfeck/e3c9540cd4ccc734e755 to your computer and use it in GitHub Desktop.
An example of a query that can be placed into a page template that displays a list of events for Event Espresso 4
<ul class="events">
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$atts = array(
'paged' => $paged,
'title' => NULL,
'limit' => 100,
'css_class' => NULL,
'show_expired' => FALSE,
'month' => NULL,
'category_slug' => NULL,
'order_by' => 'start_date',
'sort' => 'ASC'
);
// run the query
global $wp_query;
$wp_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $atts );
if (have_posts()) : while (have_posts()) : the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php do_action( 'AHEE_event_details_after_the_event_title', $post ); ?>
</li>
<?php
endwhile;
$big = 999999999; // need an unlikely integer
echo paginate_links(
array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
)
);
else:
?>
<li>No Upcoming Events</li>
<?php
endif;
// now reset the query and postdata
wp_reset_query();
wp_reset_postdata();
?>
</ul>
@lpickerill82
Copy link

Thanks for this, works like a treat. ;)

@lpickerill82
Copy link

Hi, I successfully done the event list though I need to run the query on the calendar, how do i go about doing this?

@jonathan-dejong
Copy link

Quick question, is there a reason why you override the regular wp_query rather than creating a custom query?

$event_query =  new EE_Event_List_Query( $atts );
if($event_query->have_posts()) etc…

@joshfeck
Copy link
Author

joshfeck commented Dec 5, 2014

Yes. It's not in the example. It's for using something like espresso_get_template_part( 'content', 'espresso_events' ); inside the loop.

@ErinK
Copy link

ErinK commented Feb 3, 2016

Thank you for this! Very helpful.

@robynlarsen
Copy link

@joshfeck where is the best documentation on expanding this query with particular event categories slugs?

Looking to use category_slug => 'online-courses' or query multiple categories category_slug => 'online-courses, retreats, public-speaking'

@ErinK
Copy link

ErinK commented Mar 10, 2016

I'm curious how to display events like this but excluding a category.

@ErinK
Copy link

ErinK commented Mar 10, 2016

@robynlarsen, I tried using category_slug => 'my-category' and that worked. I think for multiple categories, you might try something like an array category_slug => array('category1', 'category2')

@iammomin
Copy link

iammomin commented Dec 10, 2016

What a wonderful example.
Thanks josh.
May u help me out in further query modification?
Hope you will :)

I want to use meta_query to list events on page.
Somewhat like below code.
$atts = array(
'title' => NULL,
'limit' => 10,
'css_class' => NULL,
'show_expired' => FALSE,
'month' => NULL,
'category_slug' => NULL,
'order_by' => 'start_date',
//'order_by' => 'end_date',
'sort' => 'DESC',
'meta_query' => array(
array(
'key' => 'start_date',
'value' => '2017-01-08 08:00:00',
'type' => 'DATETIME',
'compare' => '>=',
),
)
);

I want to implement search functionality for Event Espresso and i have those fields:
State - Dropdown (How to list all state? May be Venue)
Category - Dropdown
Start Date - Datepicker
End Date - Datepicker
Keyword - input

On submit those values will be submitted and based on those , i will get filtered events that are related with those values.

So how to implement this?
Please help.
Thanks in Advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment