Support

Home Forums Event Espresso Premium Custom Shortcode for Event List

Custom Shortcode for Event List

Posted: January 8, 2016 at 9:21 am


MikeP

January 8, 2016 at 9:21 am

Hi Guys,

This shortcode was created to display events even if registration expired, but event date was still in future or is the current date. I imagine it is a bit old. Any hints on how to get this to work with latest EE3 would be helpful. After this, I’m totally back in order and will leave you all alone for a while!

Cheers!

The code was added to the bottom of /includes/shortcode.php

add_shortcode('EE_ANSWER', 'espresso_questions_answers');

function display_custom_event_list_sc($atts){
		global $wpdb,$org_options;
		global $load_espresso_scripts;
		$load_espresso_scripts = true;//This tells the plugin to load the required scripts
		extract(shortcode_atts(array('category_identifier' => 'NULL','show_expired' => 'false', 'show_secondary'=>'false','show_deleted'=>'false','show_recurrence'=>'false', 'limit' => '0', 'order_by' => 'NULL', 'css_class' => 'NULL'),$atts));

		if ($category_identifier != 'NULL'){
			$type = 'category';
		}

		$show_expired = $show_expired == 'false' ? " AND (e.end_date >= '".date ( 'Y-m-d' )."' OR e.event_status = 'O')" : '';
		$show_secondary = $show_secondary == 'false' ? " AND e.event_status != 'S' " : '';
		$show_deleted = $show_deleted == 'false' ? " AND e.event_status != 'D' " : '';
		$show_recurrence = $show_recurrence == 'false' ? " AND e.recurrence_id = '0' " : '';
		$limit = $limit > 0 ? " LIMIT 0," . $limit . " " : '';
		$order_by = $order_by != 'NULL'? " ORDER BY ". $order_by ." ASC " : " ORDER BY date(start_date), id ASC ";

		if (!empty($type) && $type == 'category'){
			$sql = "SELECT e.*, ese.start_time, ese.end_time, p.event_cost ";
			isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= ", v.name venue_name, v.address venue_address, v.city venue_city, v.state venue_state, v.zip venue_zip, v.country venue_country, v.meta venue_meta " : '';
			$sql .= " FROM " . EVENTS_CATEGORY_TABLE . " c ";
			$sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.cat_id = c.id ";
			$sql .= " JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id = r.event_id ";
			isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " vr ON vr.event_id = e.id LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = vr.venue_id " : '';
			$sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id= e.id ";
            $sql .= " JOIN " . EVENTS_PRICES_TABLE . " p ON p.event_id=e.id ";
			$sql .= " WHERE c.category_identifier = '" . $category_identifier . "' ";
			$sql .= " AND e.is_active = 'Y' ";
		}else{
			 $sql = "SELECT e.*, ese.start_time, ese.end_time, p.event_cost ";
			isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= ", v.name venue_name, v.address venue_address, v.city venue_city, v.state venue_state, v.zip venue_zip, v.country venue_country, v.meta venue_meta " : '';
			$sql .= " FROM " . EVENTS_DETAIL_TABLE . " e ";
        	isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = e.id LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = r.venue_id " : '';
			$sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id= e.id ";
            $sql .= " JOIN " . EVENTS_PRICES_TABLE . " p ON p.event_id=e.id ";
			$sql .= " WHERE e.is_active = 'Y' ";

		}

		$sql .= $show_expired;
		$sql .= $show_secondary;
		$sql .= $show_deleted;
		$sql .= $show_recurrence;
		$sql .= " GROUP BY e.id ";
		$sql .= $order_by;
		$sql .= $limit;
		//template located in event_list_dsiplay.php
		ob_start();
		//echo $sql;
		event_espresso_get_event_details($sql, $css_class,$allow_override=1);
		$buffer = ob_get_contents();
		ob_end_clean();
		return $buffer;
	}

add_shortcode('CUSTOM_EVENT_LIST', 'display_custom_event_list_sc');


Tony

  • Support Staff

January 11, 2016 at 3:40 am

Hi Michael,

The reason its not working is event_espresso_get_event_details() doesn’t allow you to pass your own SQL string to be passed to the function.

So that custom function sets up up its own $sql string, using its own shortcode paramaters, passes it to event_espresso_get_event_details() which them completely ignores that string and builds its own.

Are you using a custom version of event_espresso_get_event_details() on your site to allows for these use cases?


MikeP

January 11, 2016 at 9:11 pm

I probably was. It was an old EE3 Beta. I am now on v3.1.37.6.P

I guess my question is this:

Is there currently a way on v3.1.37.6.P to have the events list display events when the registration period has ended but the event start date is still in the future. The objective is to schedule the registration form so it becomes disabled yet still show event details for people attending.


Josh

  • Support Staff

January 12, 2016 at 8:36 am

Hi Michael,

You can show the future events that are closed for registration by opening up the event_list.php template file and edit line 422 where it has this:

//include('event_list_display.php');

You change it to this:

include('event_list_display.php');

Then you copy over event_list.php and event_list_display.php to your WordPress theme.


MikeP

January 12, 2016 at 8:46 pm

Thanks for making that super easy, Josh! Much appreciated. I’m just curious why it doesn’t work that way to begin with? I think on an educational or other non-profit use case, it may make a good option or version of the plugin. Although, I haven’t explored 4 all too much yet.


Josh

  • Support Staff

January 13, 2016 at 7:04 am

It turns out that options have a cost. We try to follow the same philosophy outlined in the WordPress Philosophies under the main heading Decisions not Options where it states:

Every time you give a user an option, you are asking them to make a decision. When a user doesn’t care or understand the option this ultimately leads to frustration. As developers we sometimes feel that providing options for everything is a good thing, you can never have too many choices, right? Ultimately these choices end up being technical ones, choices that the average end user has no interest in. It’s our duty as developers to make smart design decisions and avoid putting the weight of technical choices on our end users.

Since Event Espresso 3 was primarily for registration, the decision was made to not display events that are not open for registration on the main registration page/event list. They did make sure that it’d be customizable for those who do want to display the closed for registration events outside of the calendar.


MikeP

January 13, 2016 at 8:18 am

Makes sense – Thanks for your help!


Josh

  • Support Staff

January 13, 2016 at 9:00 am

You are welcome Michael.

The support post ‘Custom Shortcode for Event 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