Posted: April 6, 2018 at 11:54 am
Hi I’ve added custom column to Event Registrations admin table and now need to enable sorting of registrations by that column. Is there a sorting filter for that? Thank you for helping! |
|
Hi there, It turns out there is a filter for this:
To add sorting to a custom column named ‘custom_column’, you would do something like this:
|
|
Thank you. The code kind of works, but the sorting doesn’t work right. Is there still anything missing? |
|
I’m able to click on column heading, the URL shows proper information ASC and DESC by the proper field, but the sorting doesn’t work right. function tw_ee_sortable_columns( $sortable_columns, $screen ) { |
|
here is the URL – /wp-admin/admin.php?page=espresso_registrations&orderby=myCustomColumnName&order=asc |
|
What values are in your custom column? |
|
Hi This topic is to continue the older topic https://eventespresso.com/topic/sorting-by-custom-column-in-events-registration-table/ For a custom column I use unique registration code. It’s a 3 digits random number. add_filter(‘FHEE_manage_event-espresso_page_espresso_registrations_sortable_columns’, ‘tw_ee_sortable_columns’, 10, 2); function tw_ee_sortable_columns( $sortable_columns, $screen ) { |
|
I’ve merged your new thread with your older one. Ok, so when you say the sorting doesn’t work right, what happens when you sort using that field? |
|
It looks like it sorts by registration date and time instead of my custom column |
|
Here is var_dump of $sortable_columns array(6) { |
|
I renamed lottery_number to REG_code, because it was actually edited REG_code and it still saves in the database as REG_code. The lottery_number field is REG_code field that I modified. 1. Here is how I changed the REG_code to make it random within a specific event function change_reg_code($new_reg_code, $transaction, $ticket) { global $wpdb; if ( $ticket instanceof EE_Ticket ) { $attendees = $wpdb->get_results( $wpdb->prepare( $sql, $evt_id )); $new_reg_code = strval(rand(100, 999)); return $new_reg_code; 2. Then I added this new REG_code which is my random lottery number to registrations table add_filter( “FHEE_manage_event-espresso_page_espresso_registrations_columns”,”bc_filter_registration_list_table_columns”, 10, 2); function bc_filter_registration_list_table_columns( $columns, $screen ) { if ( $screen === “espresso_registrations_default” ) { } add_action( “AHEE__EE_Admin_List_Table__column_REG_code__event-espresso_page_espresso_registrations”,”bc_registration_list_table_lottery_number”, 10, 2); // Add lottery number if ( $screen === “espresso_registrations_default” && $item instanceof EE_Registration ) { $reg_code = $item->reg_code(); 3. Add sorting by the lottery number (REG_code) column function tw_ee_sortable_columns( $sortable_columns, $screen ) { if ( $screen == ‘espresso_registrations_default’ ) { Issue – when I click on Lottery number column heading I get sorting by date instead. |
|
here is the final url for the sorted column but the list is still sorted by date |
|
it is always sorted by date if I enable sorting by any other custom column |
|
Hmm, ok. Looks like we need a fix for this on our end, the orderby param is run through a switch to confirm which value is used and if the custom value doesn’t match any case there then it’s defaulting to use Reg_date. I’ve created an issue for our developers to investigate this further. |
|
Thank you! |
|
is there any update on this topic? thank you! |
|
No updates yet. We have a ticket for this which is in our queue and linked to this thread so we’ll post any updates here. |
|
Hi there, Apologies for the delay but I just wanted to let you know there are now filters in place to allow for this. You can find a working example here: https://gist.github.com/Pebblo/88f2a0a9213c716e4886a249e7709245 If you have any questions please let me know. |
|
The support post ‘Sorting by custom column in Event's registration table’ 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.