Home › Forums › Front-end Issues › Strange results when using orderby a number field › Reply To: Strange results when using orderby a number field
The loop is fine.
The problem is that the jQuery table I’m using (was using, Im trying a different script now) to SORT the data is confusing the parsed numbers with commas as regular strings, not as numbers/values so it orders as 1,100, 1000,2, 20, 2222, 6 instead of 1,2,6,20,100,1000,2222
The problem seems to be that converting the string with <?php echo number_format( floatval( get_field(‘revenue_number’) ), 0, ‘.’, ‘,’ ); ?> confuses the sorter.
If I don’t convert it and just use the regular the_field call, it sorts properly.
I don’t know if there’s a way to call the conversion in the loop prior to the while/loop or if there’s a different way to convert the output
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.