I have used the code that was provided to me in my functions file so that I could add “Organizations” to the registration list. When users sort the column alphabetically is gives back random or incorrect results. I have been paying a dev on codeable to help me with some of the customization and he said “I have reviewed the custom code for generating the organization, and it appears to be functioning correctly. However, I noticed that we still encounter issues when sorting by name, as shown in the following screenshot: https://share.cleanshot.com/WvTfhTSY5GQ2S7DQ9K41. This suggests that there may be a problem with the plugin itself, or there could be additional custom code elsewhere that we need to investigate.”
I am pasting the functions file code here to see if that is the issue that you can see, or if you need access i am happy to provide it.
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); }
/*
* This function allows you to set an array of 'allowed' fields that will be output to the registration CSV.
* The order in which they are set in the 'allowed_fields_in_order' array is the order that will be used by the CSV itself.
*/
function tw_ee_espresso_reg_report_filter_columns_ordered($csv_row, $registration_db_row)
{
$wpr_field_ids = get_transient('wpr_field_ids');
if (empty($wpr_field_ids)) {
return $csv_row;
}
// Set the allowed fields here and also set them in the order you want them to be displayed within the CSV
$allowed_fields_in_order = array_keys($csv_row);
// Get only the items that are available in wpr_field_ids
$allowed_fields_in_order = array_intersect_key(
$allowed_fields_in_order,
array_flip($wpr_field_ids)
);
// Flip the array so the values are now the keys.
$allowed_fields_in_order = array_flip($allowed_fields_in_order);
// Set the value for each of the array elements to an empty string.
// This is incase any of the above questions do not exist in the current registration's questions,
// they still need to be included in the row but the value should be nothing.
$allowed_fields_in_order = array_fill_keys(array_keys($allowed_fields_in_order), '');
// Sets $filtered_csv_row to only contain the 'allowed' fields.
$filtered_csv_row = array_intersect_key(
$csv_row,
$allowed_fields_in_order
);
// Now lets set $filtered_csv_row to use the same custom order we set $allowed_fields_in_order to
$filtered_csv_row = array_merge($allowed_fields_in_order, $filtered_csv_row);
return $filtered_csv_row;
}
add_filter('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_espresso_reg_report_filter_columns_ordered', 10, 2);
add_filter( 'generate_copyright','tu_custom_copyright' );
function tu_custom_copyright() {
?>
For Technical Support Email <a href="mailto:support@totalom.net">support@totalom.net</a>
<?php
}
add_filter(
'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
'my_custom_search_field_reg',
10,
2
);
function my_custom_search_field_reg( $where, $request ) {
if (isset($request['s']) && !empty($request['s'])) {
$search_string = '%' . sanitize_text_field($request['s']) . '%';
$where['OR*search_conditions']['Answer.ANS_value'] = array('LIKE', $search_string);
}
return $where;
}
function tw_custom_columns( $columns, $screen ) {
// This is for the 'default' registration list table
// Event Espresso -> Registrations.
if($screen == 'espresso_registrations_default'){
// EEH_Array::insert_into_array() allows you to specific a specific key
// that you want to add your additional column before/after.
// This adds the custom-reg-qst-column just before 'actions' column.
$columns = EEH_Array::insert_into_array(
$columns,
array( 'custom-reg-qst-column' => 'Organization' ),
'_REG_date'
);
}
//Add a custom-reg-qst-column column to the contact list table.
if($screen == 'espresso_registrations_event_registrations') {
//This is another method you can use that just adds the column to the end of the array.
$columns['custom-reg-qst-column'] = 'Organization';
}
return $columns;
}
add_filter('FHEE_manage_event-espresso_page_espresso_registrations_columns', 'tw_custom_columns', 10, 2);
function tw_checkin_table_custom_question( $item, $screen ){
//Sanity check to confirm we have an EE_Registration object.
if($item instanceof EE_Registration){
//Pull the answer object for Question ID 26 using the current registration.
$question_id = 26;
$answer_obj = EEM_Answer::instance()->get_registration_question_answer_object( $item, $question_id );
if ( $answer_obj instanceof EE_Answer ){
//If we have an answer object, echo the 'pretty' value for it.
echo $answer_obj->pretty_value();
}
}
}
// 'custom-reg-qst-column' in the action name here needs to be changed to match your column name set in the function above.
add_action( 'AHEE__EE_Admin_List_Table__column_custom-reg-qst-column__event-espresso_page_espresso_registrations', 'tw_checkin_table_custom_question', 10, 2 );
//Enable sorting for the custom column.
function tw_ee_sortable_columns( $sortable_columns, $screen ) {
if ( $screen == 'espresso_registrations_default' ) {
$sortable_columns['custom-reg-qst-column'] = array('custom-reg-qst-column' => false);
}
return $sortable_columns;
}
add_filter('FHEE_manage_event-espresso_page_espresso_registrations_sortable_columns', 'tw_ee_sortable_columns', 10, 2);
// The models only accept certain values for orderby, normally the column name is used but if thats custom we'll need to pass a value
// the models understand. THis sets the order by to 'Answer.ANS_value' when you select the custom column above.
function tw_ee_get_orderby_for_registrations_query( $order_by, $request)
{
if( isset($order_by['custom-reg-qst-column'] ) ) {
$fixed_order_by = array(
'Answer.ANS_value' => $order_by['custom-reg-qst-column']
);
unset($order_by['custom-reg-qst-column']);
foreach( $order_by as $key => $value) {
$fixed_order_by[$key] = $value;
}
return $fixed_order_by;
}
//Return the original order_by array.
return $order_by;
}
add_filter('FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query', 'tw_ee_get_orderby_for_registrations_query', 10, 2);
if ( file_exists( get_stylesheet_directory() . '/wpr-193430/wpr_193430.php' ) ) {
require_once ( get_stylesheet_directory() . '/wpr-193430/wpr_193430.php' );
}
add_filter('FHEE__Transactions_Admin_Page__getActionButtons__actions', 'tw_ee_add_frontend_payment_link_to_txn_actions', 10, 2);
function tw_ee_add_frontend_payment_link_to_txn_actions($actions, $transaction) {
$registration = $transaction->primary_registration();
if (
$registration instanceof EE_Registration
&& $transaction->status_ID() !== EEM_Transaction::complete_status_code
&& $registration->owes_monies_and_can_pay()
) {
$actions['frontend_payment'] = EEH_Template::get_button_or_link(
$registration->payment_overview_url(true),
esc_html__('Make Payment from the Frontend.', 'event_espresso'),
'button button--secondary',
'dashicons dashicons-money'
);
}
return $actions;
}
I was getting frustrated with the dev I hired so I pasted the whole thing into Gemini and asked it why is my alphabetical sorting broken? and after a couple tries it came up with that and i pasted in my functions and now the sorting works. I am a front end WP guy, functions files beyond basic things to enque child themes etc and pating things i find are about the limit of my expertise.
Hmm, strange! I can’t find the filter, but it could be one of the dynamic filters we apply on the fly using the class and method names.
Either way, I’m glad you found a solution that works for your setup 🙂
Viewing 4 reply threads
The support post ‘Sorting by Organization Alphabetically is broken’ 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.
Support forum for Event Espresso 3 and Event Espresso 4.