Support

Home Forums Event Espresso Premium Displaying event city on past events list

Displaying event city on past events list

Posted: July 8, 2014 at 5:00 am

Viewing 10 reply threads


Daniele Pavinato

July 8, 2014 at 5:00 am

Hi,

I need help. I created a page that display the past events archive, but i need to retrieve the city of the past event.

See the code belaow used for this purpose:

<code>add_action(&#039;action_hook_espresso_custom_template_past-events&#039;,&#039;espresso_custom_template_past_events&#039;);

function espresso_custom_template_past_events(){

	global $this_event_id, $events, $wpdb;
	foreach ($events as $event){
		$button_text 		= __(&#039;&#039;, &#039;event_espresso&#039;);
		$alt_button_text	= __(&#039;View Details&#039;, &#039;event_espresso&#039;);//For alternate registration pages
		$externalURL 		= $event-&gt;externalURL;
		$button_text		= !empty($externalURL) ? $alt_button_text : $button_text;
		$registration_url 	= !empty($externalURL) ? $externalURL : espresso_reg_url($event-&gt;id);
	}

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

	foreach ($temp_cats as $category) { 

		$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);

		if( !empty($temp_start_end) ) : ?&gt;
		
		&lt;li&gt;
			&lt;ul&gt;

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

			//Get all pasts event
		    foreach ($temp_start_end as $past_event){

		    	var_dump($past_event);

		    	$string = $past_event-&gt;event_desc;
				$match = wp_extract_urls( $string );?&gt;

				 &lt;li class=&quot;event&quot;&gt;
					&lt;div class=&quot;title&quot;&gt;&lt;?php echo $past_event-&gt;event_name; ?&gt;&lt;/div&gt;
					&lt;div class=&quot;date&quot;&gt;&lt;?php past_date_check($past_event); ?&gt;&lt;/div&gt;
					&lt;div class=&quot;place&quot;&gt;
						&lt;?php
							echo do_shortcode(&#039;[ESPRESSO_VENUE event_id=&quot;&#039; . $event-&gt;id . &#039;&quot; show_image=&quot;false&quot; show_title=&quot;false&quot; show_description=&quot;false&quot; show_address=&quot;false&quot; show_additional_details=&quot;false&quot; show_google_map_link=&quot;false&quot; show_map_image=&quot;false&quot; outside_wrapper=&quot;span&quot; title_wrapper=&quot;span&quot; ]&#039;);
							// if($past_event-&gt;city !== &quot;&quot;){
							// 	if($past_event-&gt;venue_title !== &quot;&quot;){								
							// 		echo $past_event-&gt;venue_title . &#039; - &#039; . $past_event-&gt;city;
							// 	}else{
							// 		echo $past_event-&gt;city;	
							// 	} 
							// } 
						?&gt;
					&lt;/div&gt;
					&lt;a href=&quot;&lt;?php echo stripslashes($match[0]); ?&gt;&quot;&gt;Programma&lt;/a&gt;
					&lt;br&gt;

					&lt;?php if($match[1]) : ?&gt;
					&lt;a href=&quot;&lt;?php echo stripslashes($match[1]); ?&gt;&quot;&gt;Relazioni&lt;/a&gt;
					&lt;?php endif; ?&gt;
					
				&lt;/li&gt;

		&lt;?php  }  ?&gt;

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

&lt;?php 
	
	endif;

	} 

?&gt;</code>


Daniele Pavinato

July 8, 2014 at 5:01 am

I’m sorry, the correct one is this:

<code>add_action(&#039;action_hook_espresso_custom_template_past-events&#039;,&#039;espresso_custom_template_past_events&#039;);

function espresso_custom_template_past_events(){

	global $this_event_id, $events, $wpdb;
	foreach ($events as $event){
		$button_text 		= __(&#039;&#039;, &#039;event_espresso&#039;);
		$alt_button_text	= __(&#039;View Details&#039;, &#039;event_espresso&#039;);//For alternate registration pages
		$externalURL 		= $event-&gt;externalURL;
		$button_text		= !empty($externalURL) ? $alt_button_text : $button_text;
		$registration_url 	= !empty($externalURL) ? $externalURL : espresso_reg_url($event-&gt;id);
	}

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

	foreach ($temp_cats as $category) { 

		$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);

		if( !empty($temp_start_end) ) : ?&gt;
		
		&lt;li&gt;
			&lt;ul&gt;

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

			//Get all pasts event
		    foreach ($temp_start_end as $past_event){

		    	$string = $past_event-&gt;event_desc;
				$match = wp_extract_urls( $string );?&gt;

				 &lt;li class=&quot;event&quot;&gt;
					&lt;div class=&quot;title&quot;&gt;&lt;?php echo $past_event-&gt;event_name; ?&gt;&lt;/div&gt;
					&lt;div class=&quot;date&quot;&gt;&lt;?php past_date_check($past_event); ?&gt;&lt;/div&gt;
					&lt;div class=&quot;place&quot;&gt;
						&lt;?php 
							if($past_event-&gt;city !== &quot;&quot;){
								if($past_event-&gt;venue_title !== &quot;&quot;){								
									echo $past_event-&gt;venue_title . &#039; - &#039; . $past_event-&gt;city;
								}else{
									echo $past_event-&gt;city;	
								} 
							} 
						?&gt;
					&lt;/div&gt;
					&lt;a href=&quot;&lt;?php echo stripslashes($match[0]); ?&gt;&quot;&gt;Programma&lt;/a&gt;
					&lt;br&gt;

					&lt;?php if($match[1]) : ?&gt;
					&lt;a href=&quot;&lt;?php echo stripslashes($match[1]); ?&gt;&quot;&gt;Relazioni&lt;/a&gt;
					&lt;?php endif; ?&gt;
					
				&lt;/li&gt;

		&lt;?php  }  ?&gt;

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

&lt;?php 
	
	endif;

	} 

?&gt;</code>


Dean

July 8, 2014 at 6:52 am

Hi,

If you are using the Venue Manager then the venue details are held in another table (events_venue) and there is also a relational table (events_venue_rel).

You could either do acouple more SQL queries – a request to events_venue_rel to get the associated venue and then a request to events_venue to get the actual venue data.

Or you could do a request to events_venue_rel for the associated venue id and then use the ESPRESSO_VENUE shortcode in a do_shortcode() function.

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


Daniele Pavinato

July 8, 2014 at 7:02 am

Thanks Dean, but I REALLY need to solve this problem sooner possible.
So, can you write for me an example that I can to modify as my needs?


Daniele Pavinato

July 8, 2014 at 7:28 am

Solved!


Dean

July 8, 2014 at 7:38 am

Glad you got it figured out!


Daniele Pavinato

July 9, 2014 at 3:57 am

Hi, this line code $sql_past_events = "SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE end_date < DATE(NOW()) AND category_id =" . $category->id; retrieves all past event from a specific category but not in DESC o ASC order.

I need that are in ASC order (by start_date or end_date), but the start_date or end_date column is a string type.

How can i display all past event ordered by ASC start or end date?

Thanks


Daniele Pavinato

July 9, 2014 at 4:16 am

This is an example


Tony

  • Support Staff

July 9, 2014 at 4:46 am

Hi Daniele,

You’ll want to use the ‘ORDER BY’ SQL Keyword.

Basically add:

‘ORDER BY date(start_date), id ASC’

To the end of the Query. So something like:

$sql_past_events = "SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE end_date < DATE(NOW()) AND category_id =" . $category->id . " ORDER BY date(start_date), id ASC";

Should work as you are expecting.


Daniele Pavinato

July 9, 2014 at 4:54 am

Thank you very very much!! Mi mistake was to write ORDER BY start_date without the function date()


Tony

  • Support Staff

July 9, 2014 at 5:38 am

You are most welcome Daniele 🙂

I will mark this thread resolved, if you do have any other questions feel free to start another.

Viewing 10 reply threads

The support post ‘Displaying event city on past events list’ 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