Task #436
Plugin Update #279: Events Manager Update
Show recurrent event as 1 event
| Status: | New | Start date: | 03/09/2012 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | - | |||
| Target version: | - | |||
| Tag: | events |
Description
Recurrent events should be counted as a single Event, not individual events.
functions-events.php > Line 3
// add filter to enable recurrence_id arg in count function
add_filter('em_events_count', 'nycga_allow_recurrence', 2, 10);
function nycga_allow_recurrence ($count, $args)
{
if ( isset($args['recurrence_id']))
{
global $wpdb;
$count = true;
$events_table = EM_EVENTS_TABLE;
$locations_table = EM_LOCATIONS_TABLE;
// todo: is it a bug that get_default_search( $args ) does not return a 'recurrence_id'?
$recurrence_id = (int)$args['recurrence_id'];
$args = EM_Events::get_default_search($args);
if ( isset( $args['recurrence_id'] ) )
$recurrence_id = $args['recurrence_id'];
$conditions = EM_Events::build_sql_conditions($args);
$conditions['recurrence'] = "`recurrence_id`='" . $recurrence_id . "'";
unset($conditions['recurring']);
$limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
$offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
//Put it all together
$where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
//Get ordering instructions
$EM_Event = new EM_Event();
$accepted_fields = $EM_Event->get_fields(true);
$orderby = EM_Events::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
//Now, build orderby sql
$orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
//Create the SQL statement and execute
$selectors = ( $count ) ? 'COUNT(*)':'*';
$sql = "
SELECT $selectors FROM $events_table
LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
$where
$orderby_sql
$limit $offset
";
return $wpdb->get_var($sql);
}
return $count;
}
History
Updated by Pea Lutz about 1 year ago
- Parent task set to #279
Updated by Lippe Lippe about 1 year ago
- Tracker changed from 8 to Task