-
-
Save Pebblo/78334c82674e9da3bb4d4375f06f273f to your computer and use it in GitHub Desktop.
This function adds a 'Year' dropdown that will display any year you have registration in, you can select the year and view registrations specifically for that year.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Please do not include the opening PHP tag if you already have one. | |
// Adds a 'year' filter to the registration admin list table. | |
add_filter('FHEE__Extend_EE_Registrations_List_Table__filters', 'tw_ee_add_year_filter_to_reg_list_table', 10, 3); | |
function tw_ee_add_year_filter_to_reg_list_table( $filters, $list_table_object, $screen ) { | |
$where = array(); | |
//Check if we have a current reg_status set. | |
if(! empty( EE_Registry::instance()->REQ->get('_reg_status') ) ) { | |
$where['STS_ID'] = EE_Registry::instance()->REQ->get('_reg_status'); | |
} | |
//Check if we are looking for a specific category | |
$cur_category = EE_Registry::instance()->REQ->get('EVT_CAT'); | |
if ($cur_category > 0) { | |
$where['Event.Term_Taxonomy.term_id'] = $cur_category; | |
} | |
//Build out the query to pull the years you have registrations for. | |
$query_params[0] = $where; | |
$query_params['group_by'] = array('reg_year'); | |
$query_params['order_by'] = array('REG_date' => 'DESC'); | |
$columns_to_select = array( | |
'reg_year' => array('YEAR(REG_date)', '%s'), | |
); | |
$regdtts = EEM_Registration::instance()->get_all_wpdb_results($query_params, OBJECT, $columns_to_select); | |
// setup vals for select input helper | |
$options = array( | |
0 => array( | |
'text' => __('Select a Year', 'event_espresso'), | |
'id' => '' | |
) | |
); | |
foreach ($regdtts as $regdtt) { | |
$year = $regdtt->reg_year; | |
$options[] = array( | |
'text' => $year, | |
'id' => $year | |
); | |
} | |
//Add the new 'Year' dropdown to the available filters. | |
$filters[] = EEH_Form_Fields::select_input('year_range', $options, EE_Registry::instance()->REQ->get('year_range'), '', 'wide'); | |
return $filters; | |
} | |
add_filter('FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', 'tw_ee_reg_list_table_year_where', 10, 2); | |
function tw_ee_reg_list_table_year_where( $where, $request ) { | |
//Check we have a year set to filter on the request. | |
if( !empty( $request['year_range'] ) ) { | |
//Sanatize the input. | |
$year_requested = sanitize_text_field($request['year_range']); | |
//Build out the query using the Janurary 1st - 31st December based o the current year selected. | |
$where['REG_date'] = array( | |
'BETWEEN', | |
array( | |
EEM_Registration::instance()->convert_datetime_for_query( | |
'REG_date', | |
$year_requested . '-01-01 00:00:00', | |
'Y-m-d H:i:s' | |
), | |
EEM_Registration::instance()->convert_datetime_for_query( | |
'REG_date', | |
$year_requested . '-12-31 23:59:59', | |
'Y-m-d H:i:s' | |
), | |
), | |
); | |
} | |
return $where; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment