Support

Home Forums Event Espresso Premium Sorting problem (spaces left) in Events Table – only uses 1st digit

Sorting problem (spaces left) in Events Table – only uses 1st digit

Posted: September 12, 2016 at 1:18 am


AnnaTanzt

September 12, 2016 at 1:18 am

Hi there,

I added a column”spaces left” to my events table. But when people sort with that column, it uses the 1st digit do sort. (i.e. 1, 11, 12, 2, 24, 3 …)

And, can I change how many events are listed? Right now, there are only 10. I’d like there to be 20 or 40

How can that be fixed?

Best!
Anna


Josh

  • Support Staff

September 12, 2016 at 8:59 am

You can change the amount of events that are listed by clicking the screen options tab, then set the value to a higher number.

In the code that you used to add a spaces left column, you’ll probably need to make sure that the data-type is an integer, it sounds like it’s sorting those as strings, which will make it sort the way you describe.


AnnaTanzt

September 12, 2016 at 2:50 pm

Hi Josh,

I think I figured out how I added it. I followed these instructions by Lorenzo, I believe: Instruction
It is under the following path: wp-content / uploads / espresso / templates / espresso-events-table-template.template.php

and has this code:
<?php
// Options
$date_format = get_option( ‘date_format’ );
$time_format = get_option( ‘time_format’ );
// Load Venue View Helper
EE_Registry::instance()->load_helper(‘Venue_View’);
//Defaults
$reg_button_text = !isset($reg_button_text) ? __(‘Register’, ‘event_espresso’) : $reg_button_text;
$alt_button_text = !isset($alt_button_text) ? __(‘View Details’, ‘event_espresso’) : $alt_button_text;//For alternate registration pages
$sold_out_button_text = !isset($sold_out_button_text) ? __(‘Sold Out’, ‘event_espresso’) : $sold_out_button_text;//For sold out events
$category_filter_text = !isset($category_filter_text) ? __(‘Category Filter’, ‘event_espresso’) : $category_filter_text;

if ( have_posts() ) :
// allow other stuff
do_action( ‘AHEE__espresso_events_table_template_template__before_loop’ );
?>

<?php if ($category_filter != ‘false’){ ?>
<p class=”category-filter”>
<label><?php echo $category_filter_text; ?></label>
<select class=”” id=”ee_filter_cat”>
<option class=”ee_filter_show_all”><?php echo __(‘Show All’, ‘event_espresso’); ?></option>
<?php
$taxonomy = array(‘espresso_event_categories’);
$args = array(‘orderby’=>’name’,’hide_empty’=>true);
$ee_terms = get_terms($taxonomy, $args);

foreach($ee_terms as $term){
echo ‘<option class=”‘ . $term->slug . ‘”>’. $term->name . ‘</option>’;
}
?>
</select>
</p>
<?php } ?>

<?php if ($footable != ‘false’ && $table_search != ‘false’){ ?>
<p>
<?php echo __(‘Search:’, ‘event_espresso’); ?> <input id=”filter” type=”text”/>
</p>
<?php } ?>

<table id=”ee_filter_table” class=”espresso-table footable table” data-page-size=”<?php echo $table_pages; ?>” data-filter=”#filter”>
<thead class=”espresso-table-header-row”>
<tr>
<th class=”th-group”><?php _e(‘Event’,’event_espresso’); ?></th>
<th class=”th-group”><?php _e(‘Venue’,’event_espresso’); ?></th>
<th class=”th-group”><?php _e(‘Freie Plätze’,’event_espresso’); ?></th>
<th class=”th-group”><?php _e(‘Date’,’event_espresso’); ?></th>
<th class=”th-group” data-sort-ignore=”true”></th>
</tr>
</thead>
<?php if ($footable != ‘false’ && $table_paging != ‘false’){ ?>
<tfoot>
<tr>
<td colspan=”5″>
<div class=”pagination pagination-centered”></div>
</td>
</tr>
</tfoot>
<?php } ?>
<tbody>

<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the post TYPE-specific template for the content.
global $post;

//Debug
//d( $post );

//Get the category for this event
$event = EEH_Event_View::get_event();
if ( $event instanceof EE_Event ) {
if ( $event_categories = get_the_terms( $event->ID(), ‘espresso_event_categories’ )) {
// loop thru terms and create links
$category_slugs = ”;
foreach ( $event_categories as $term ) {
$category_slugs[] = $term->slug;
}
$category_slugs = implode(‘ ‘, $category_slugs);
} else {
// event has no terms
$category_slugs = ”;
}

}
//Create the event link
$external_url = $post->EE_Event->external_url();
$button_text = !empty($external_url) ? $alt_button_text : $reg_button_text;
$registration_url = !empty($external_url) ? $post->EE_Event->external_url() : $post->EE_Event->get_permalink();

//Create the register now button
$live_button = ‘ID.'” class=”a_register_link” href=”‘.$registration_url.'”>’.$button_text.’‘;

if ( $event->is_sold_out() || $event->is_sold_out(TRUE ) ) {
$live_button = ‘ID.'” class=”a_register_link_sold_out a_register_link” href=”‘.$registration_url.'”>’.$sold_out_button_text.’‘;
}

// If the show_all_datetimes parameter is set set the limit to NULL to pull them all,
// if not default to only dipslay a single datetime.
$datetime_limit = $show_all_datetimes ? NULL : 1;

// Pull the datetimes for this event order by start_date/time
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, $datetime_limit );

// Reset the datetimes pointer to the earlest datetime and use that one.
$datetime = reset( $datetimes );

?>
<tr class=”espresso-table-row <?php echo $category_slugs; ?>”>
<td class=”event_title event-<?php echo $post->ID; ?>”><?php echo $post->post_title; ?></td>
<td class=”venue_title event-<?php echo $post->ID; ?>”><?php espresso_venue_name( NULL, FALSE ); ?></td>
<td class=”space_remaining event-<?php echo $post->ID; ?>”><?php $total_spaces_left = $datetime->spaces_remaining(); echo $total_spaces_left === INF ? ‘<span class=”smaller-text”>’ . __( ‘∞ ‘, ‘event_espresso’ ) . ‘</span>’ : $total_spaces_left; ?></td>
<td class=”start_date event-<?php echo $post->ID; ?>” data-value=”<?php echo $datetime->get_raw( ‘DTT_EVT_start’ ); ?>”>
<ul class=”ee-table-view-datetime-list”>
<?php
// Loop over each datetime we have pulled from the database and output
foreach ($datetimes as $datetime) {
?>
<li class=”datetime-id-<?php echo $datetime->ID(); ?>”>
<?php echo date_i18n( $date_format . ‘ ‘ . $time_format, strtotime( $datetime->start_date_and_time(‘Y-m-d’, ‘H:i:s’) ) ); ?>

<?php
//end foreach $datetimes
}
?>

</td>
<td class=”td-group reg-col” nowrap=”nowrap”><?php echo $live_button; ?></td>
</tr>
<?php

endwhile;
echo ‘</table>’;
// allow moar other stuff
do_action( ‘AHEE__espresso_events_table_template_template__after_loop’ );

else :
// If no content, include the “No posts found” template.
espresso_get_template_part( ‘content’, ‘none’ );

endif;

I don’t know how to make sure the data type is an integer, though.

I know how to change the amount of data sets shown on the backend. I would like to change it on the front end, so the events table on our website shows all events at once (see our website)

Thanks a lot for your help.
Anna


Josh

  • Support Staff

September 12, 2016 at 3:36 pm

In the future, please do not post the contents of an entire template file into a forum reply. Instead, please post them into a github gist or into a paste bin and link here.

So the code that you posted does not have a datatype set for that spaces left column. e.g.

<?php $total_spaces_left = $datetime->spaces_remaining(); ?>
<td class="space_remaining event" 
data-value="<?php echo $total_spaces_left; ?>"> 
<?php echo $total_spaces_left === INF ? '<span class="smaller-text">∞ </span>' : $total_spaces_left; ?></td>

The support post ‘Sorting problem (spaces left) in Events Table – only uses 1st digit’ 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