Support

Home Forums Event Espresso Premium Past event snippet

Past event snippet

Posted: January 16, 2014 at 8:19 am


Daniele Pavinato

January 16, 2014 at 8:19 am

Hi,

I found the Josh script for display past events:

<code>&lt;ul&gt;
&lt;?php 
global $wpdb;
$tablename = $wpdb-&gt;prefix . events_detail;
$pastevents = $wpdb-&gt;get_results(&quot;SELECT * FROM $tablename WHERE start_date &lt; curdate() AND event_status &lt;&gt; &#039;D&#039; &quot;);
 foreach ( $pastevents as $pastevent ){
 echo &#039;&lt;li&gt;&lt;a href=&quot;&#039; . espresso_reg_url($pastevent-&gt;id) . &#039;&quot;&gt;&#039; . stripslashes($pastevent-&gt;event_name) . &#039;&lt;/a&gt;&lt;/li&gt;&#039;;
 }
?&gt;
&lt;/ul&gt;</code>

If I am right, this snippet should display a list of past event, right?
Should it be configured?
I need to display the past events grouped by category (2010, 2011, 2012, ect.). Is possible?

For the single past event, how should be the template? How can I set the page for display the past events?


Josh

  • Support Staff

January 17, 2014 at 9:48 am

Hi there,

The snippet will display a list of past events, but it does not group events by category. If you are categorizing the events by year, then you don’t need to use this snippet. The [EVENT_LIST] shortcode will work out of the box for this.


Daniele Pavinato

January 17, 2014 at 11:05 am

I’m not sure if I have understood correctly… Is possible with [EVENT_LIST] to display the past event categorized?


Josh

  • Support Staff

January 17, 2014 at 11:19 am

If the events are assigned to categories, yes.

The event list shortcode documentation shows the parameters that you can use to display past events that are in specific categories:

https://eventespresso.com/wiki/shortcodes-template-variables/#event-list


Daniele Pavinato

January 18, 2014 at 1:41 am

I need an extra explanation about that.
In the documentation I don’t see anything about past events. I see that is possible to show events by category, but how do I display only past events?


Daniele Pavinato

January 18, 2014 at 7:48 am

I solved this getting the data directly from the DB tables:

<code>function espresso_custom_template_past_events(){

	global $this_event_id, $events, $wpdb;
	
	//Get all pasts event data

	//Get all categories data
	$sql_cat_name = &quot; SELECT * FROM &quot; . EVENTS_CATEGORY_TABLE;
	$temp_cats = $wpdb-&gt;get_results($sql_cat_name); ?&gt;

	&lt;ul class=&quot;small-block-grid-1 medium-block-grid-3 large-block-grid-4&quot;&gt;

	&lt;?php

	foreach ($temp_cats as $category) { ?&gt;
		&lt;li&gt;
			&lt;ul&gt;

			&lt;?php echo &#039;&lt;h3&gt;&#039;.$category-&gt;category_name.&#039;&lt;/h3&gt;&#039;;

			$sql_start_end = &quot;SELECT * FROM &quot; . EVENTS_DETAIL_TABLE . &quot; WHERE end_date &lt; DATE(NOW()) AND category_id =&quot; . $category-&gt;id;

			$temp_start_end = $wpdb-&gt;get_results($sql_start_end);

			//var_dump($temp_start_end);
		    foreach ($temp_start_end as $past_event){  ?&gt;

				 &lt;li&gt;

					&lt;div class=&quot;event&quot;&gt;
						&lt;div class=&quot;title&quot;&gt;
							&lt;a href=&quot;&lt;?php echo espresso_reg_url($past_event-&gt;id); ?&gt;&quot;&gt;
								&lt;?php echo stripslashes_deep($past_event-&gt;event_name) ?&gt;
							&lt;/a&gt;
						&lt;/div&gt;
					&lt;/div&gt;

				&lt;/li&gt;
		
		&lt;?php  }  ?&gt;

		&lt;/ul&gt;
	&lt;/li&gt;

	&lt;?php } ?&gt;

	&lt;/ul&gt;

&lt;?php }</code>

I need to know one more thing: I want to open the past event in a different template page (not the same for the ACTIVES/OPENS event).

I have an archive of pasts event and i want to use the same page to display the past event.

In my code I added the espresso_reg_url($past_event->event_name) to open the past event and bypass the NOT_ACTIVE check, but this function redirect me in the registration event template.

How can I open pasts event in a different single event (eventually registration) template?

Am I enough clear?

Thanks.

The support post ‘Past event snippet’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso