The Events Calendar Shortcode - Version 1.8

Version Description

  • Adds new orderby='title' option
  • Fixes resetting the WordPress global query instead of just the post data
Download this release

Release Info

Developer brianhogg
Plugin Icon 128x128 The Events Calendar Shortcode
Version 1.8
Comparing to
See all releases

Code changes from version 1.7.3 to 1.8

readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: brianhogg
3
  Tags: event, events, calendar, shortcode, modern tribe
4
  Requires at least: 4.1
5
  Tested up to: 4.9
6
- Stable tag: 1.7.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -155,6 +155,10 @@ The [pro version of the plugin](https://eventcalendarnewsletter.com/the-events-c
155
 
156
  == Upgrade Notice ==
157
 
 
 
 
 
158
  = 1.7.3 =
159
  * Hide the "at" when using venue='true' and an event has no venue
160
  * Adds additional WordPress filters to hide certain events
@@ -238,6 +242,10 @@ Fix missing ul
238
 
239
  == Changelog ==
240
 
 
 
 
 
241
  = 1.7.3 =
242
  * Hide the "at" when using venue='true' and an event has no venue
243
  * Adds additional WordPress filters to hide certain events
3
  Tags: event, events, calendar, shortcode, modern tribe
4
  Requires at least: 4.1
5
  Tested up to: 4.9
6
+ Stable tag: 1.8
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
155
 
156
  == Upgrade Notice ==
157
 
158
+ = 1.8 =
159
+ * Adds new orderby='title' option
160
+ * Fixes resetting the WordPress global query instead of just the post data
161
+
162
  = 1.7.3 =
163
  * Hide the "at" when using venue='true' and an event has no venue
164
  * Adds additional WordPress filters to hide certain events
242
 
243
  == Changelog ==
244
 
245
+ = 1.8 =
246
+ * Adds new orderby='title' option
247
+ * Fixes resetting the WordPress global query instead of just the post data
248
+
249
  = 1.7.3 =
250
  * Hide the "at" when using venue='true' and an event has no venue
251
  * Adds additional WordPress filters to hide certain events
templates/admin-page.php CHANGED
@@ -70,6 +70,8 @@
70
  <h3>orderby</h3>
71
  <p><?php echo esc_html( __( 'Used to order by the end date instead of the start date.', 'the-events-calendar-shortcode' ) ); ?></p>
72
  <blockquote>[ecs-list-events orderby='enddate']</blockquote>
 
 
73
  <?php do_action( 'ecs_admin_page_options_after' ); ?>
74
 
75
  </div>
70
  <h3>orderby</h3>
71
  <p><?php echo esc_html( __( 'Used to order by the end date instead of the start date.', 'the-events-calendar-shortcode' ) ); ?></p>
72
  <blockquote>[ecs-list-events orderby='enddate']</blockquote>
73
+ <p><?php echo esc_html( __( 'You can also use this to order by title if you wish:', 'the-events-calendar-shortcode' ) ); ?></p>
74
+ <blockquote>[ecs-list-events orderby='title']</blockquote>
75
  <?php do_action( 'ecs_admin_page_options_after' ); ?>
76
 
77
  </div>
the-events-calendar-shortcode.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: The Events Calendar Shortcode
4
  Plugin URI: https://eventcalendarnewsletter.com/the-events-calendar-shortcode/
5
  Description: An addon to add shortcode functionality for <a href="http://wordpress.org/plugins/the-events-calendar/">The Events Calendar Plugin by Modern Tribe</a>.
6
- Version: 1.7.3
7
  Author: Event Calendar Newsletter
8
  Author URI: https://eventcalendarnewsletter.com/the-events-calendar-shortcode
9
  Contributors: brianhogg
@@ -38,7 +38,7 @@ class Events_Calendar_Shortcode
38
  *
39
  * @since 1.0.0
40
  */
41
- const VERSION = '1.7.3';
42
 
43
  private $admin_page = null;
44
 
@@ -134,10 +134,10 @@ class Events_Calendar_Shortcode
134
  * Check if events calendar plugin method exists
135
  */
136
  if ( !function_exists( 'tribe_get_events' ) ) {
137
- return;
138
  }
139
 
140
- global $wp_query, $post;
141
  $output = '';
142
 
143
  $atts = shortcode_atts( apply_filters( 'ecs_shortcode_atts', array(
@@ -199,7 +199,7 @@ class Events_Calendar_Shortcode
199
  $meta_date_compare = '<';
200
  }
201
 
202
- // Key
203
  if ( str_replace( ' ', '', trim( strtolower( $atts['key'] ) ) ) == 'startdate' ) {
204
  $atts['key'] = '_EventStartDate';
205
  } else {
@@ -209,6 +209,8 @@ class Events_Calendar_Shortcode
209
  // Orderby
210
  if ( str_replace( ' ', '', trim( strtolower( $atts['orderby'] ) ) ) == 'enddate' ) {
211
  $atts['orderby'] = '_EventEndDate';
 
 
212
  } else {
213
  $atts['orderby'] = '_EventStartDate';
214
  }
@@ -260,8 +262,8 @@ class Events_Calendar_Shortcode
260
  'hide_upcoming' => true,
261
  'posts_per_page' => $atts['limit'],
262
  'tax_query'=> $atts['event_tax'],
263
- 'meta_key' => ( trim( $atts['orderby'] ) ? $atts['orderby'] : $atts['key'] ),
264
- 'orderby' => 'meta_value',
265
  'author' => $atts['author'],
266
  'order' => $atts['order'],
267
  'meta_query' => apply_filters( 'ecs_get_meta_query', array( $atts['meta_date'] ), $atts, $meta_date_date, $meta_date_compare ),
@@ -365,7 +367,7 @@ class Events_Calendar_Shortcode
365
  $output .= apply_filters( 'ecs_no_events_found_message', sprintf( translate( $atts['message'], 'the-events-calendar' ), tribe_get_event_label_plural_lowercase() ), $atts );
366
  } // endif
367
 
368
- wp_reset_query();
369
 
370
  return $output;
371
  }
3
  Plugin Name: The Events Calendar Shortcode
4
  Plugin URI: https://eventcalendarnewsletter.com/the-events-calendar-shortcode/
5
  Description: An addon to add shortcode functionality for <a href="http://wordpress.org/plugins/the-events-calendar/">The Events Calendar Plugin by Modern Tribe</a>.
6
+ Version: 1.8
7
  Author: Event Calendar Newsletter
8
  Author URI: https://eventcalendarnewsletter.com/the-events-calendar-shortcode
9
  Contributors: brianhogg
38
  *
39
  * @since 1.0.0
40
  */
41
+ const VERSION = '1.8';
42
 
43
  private $admin_page = null;
44
 
134
  * Check if events calendar plugin method exists
135
  */
136
  if ( !function_exists( 'tribe_get_events' ) ) {
137
+ return '';
138
  }
139
 
140
+ global $post;
141
  $output = '';
142
 
143
  $atts = shortcode_atts( apply_filters( 'ecs_shortcode_atts', array(
199
  $meta_date_compare = '<';
200
  }
201
 
202
+ // Key, used in filtering events by date
203
  if ( str_replace( ' ', '', trim( strtolower( $atts['key'] ) ) ) == 'startdate' ) {
204
  $atts['key'] = '_EventStartDate';
205
  } else {
209
  // Orderby
210
  if ( str_replace( ' ', '', trim( strtolower( $atts['orderby'] ) ) ) == 'enddate' ) {
211
  $atts['orderby'] = '_EventEndDate';
212
+ } elseif ( trim( strtolower( $atts['orderby'] ) ) == 'title' ) {
213
+ $atts['orderby'] = 'title';
214
  } else {
215
  $atts['orderby'] = '_EventStartDate';
216
  }
262
  'hide_upcoming' => true,
263
  'posts_per_page' => $atts['limit'],
264
  'tax_query'=> $atts['event_tax'],
265
+ 'meta_key' => ( ( trim( $atts['orderby'] ) and 'title' != $atts['orderby'] ) ? $atts['orderby'] : $atts['key'] ),
266
+ 'orderby' => ( $atts['orderby'] == 'title' ? 'title' : 'meta_value' ),
267
  'author' => $atts['author'],
268
  'order' => $atts['order'],
269
  'meta_query' => apply_filters( 'ecs_get_meta_query', array( $atts['meta_date'] ), $atts, $meta_date_date, $meta_date_compare ),
367
  $output .= apply_filters( 'ecs_no_events_found_message', sprintf( translate( $atts['message'], 'the-events-calendar' ), tribe_get_event_label_plural_lowercase() ), $atts );
368
  } // endif
369
 
370
+ wp_reset_postdata();
371
 
372
  return $output;
373
  }