Posted: December 31, 2012 at 9:58 pm
I’ve created categories that output to a table. They are Alphanumeric, but always start with a number. Currently, their output seems random. I’d like to order them from low to high (8U 9U 10U, etc.) Here is an example. It’s the last column of the table I’m trying to re-order http://utrip.pickorange.com/event-list/ I saw this similar post, but couldn’t figure it out as the code has changed around a bit. https://eventespresso.com/forums/2010/09/order-listing-of-categories/ I’m aware that manual sorting is on the list for future enhancements, but for now, is there a way I can accomplish this with some kind of sort()? Thanks! |
|
The order is most likely by category ID, which should correspond with the order in which the categories were created. You could go and rename all your categories so they are sequential that way. The other option would be modifying the SQL query. Depending on where you are trying to make this happen would determine what template files would need to be modified. |
|
I don’t think it’s SQL ID. Here is the result of my Category table. Yet I’m still getting results like this: I’m using the custom file template espresso_table.php to get the table. Is there any kind of JS or PHP sort I can apply to just that cell? |
|
Any other suggestions? |
|
I’ve found that I can control the order by editing the events_category_rel values in phpMyAdmin. I have over 250 rows and would rather not edit them all every time I load an event. Is there some kind of code that will keep this table sorted properly going forward? Is there any kind of sql query I can run on the events already loaded to fix this? I’m really stuck here and need to get this fixed. Thanks! |
|
|
Hi, You could try the PHP function sort This is an example from the link above. Basically you run the array through the sort function. You might not even need the foreach
|
This option shows a defined array. Mine is not defined as it’s determined by which categories are clicked on the event? I don’t understand why this is happening if the IDs of all of the categories are in order in the MySQL database? There must be some code in EE somewhere along the way that can tell the database to spit out the category results in ASC order. I don’t care if I have to modify core files. This is a necessity. Here is my code if it helps:
Ideally, I’d love to modify Category_Name as a custom shortcode and add the code here. Possible? |
|
ummm… that’s not what I pasted as my code.
|
|
Well, I guess code pasting doesn’t work. |
|
|
Hi Jeff, This will do what you want, but with one criteria – single digit numbers require a zero in front – eg 8U becomes 08U, otherwise in order, 10U comes before 8U (1 before 8).
|
Found out that PHP has built in Natural Support which solved the 0 in front issue. Changed your code from Problem solved! No need for 0’s and it’s all ordered correctly. Thank you so much! This has eluded me for weeks now! |
|
|
Hi Jeff, No problem, and thanks for posting the |
The support post ‘Alphabetizing category results’ 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.