Skip Navigation

[Resolved] Sorting Columns with Dollar Signs & Commas

This thread is resolved. Here is a description of the problem and solution.

Problem:

Sorting columns that include numbers with dollar signs & commas

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/sorting-columns-with-dollar-signs-commas/#post-1290195

Relevant Documentation:

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 2.24 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by marcusC-4 5 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1289219

I previously had a support thread about sorting columns that include numbers with dollar signs & commas. At the time, the support provided worked great. Minesh applied a custom function that allowed sorting to work very well.

However, the code doesn’t appear to be working anymore as I cannot sort the columns as expected.

Here is the original support thread: https://toolset.com/forums/topic/remove-dollar-sign-commas-from-numbers-field-values/

And here is the URL in question: hidden link

I’d love to know how to make these columns sortable again by the total size of the number instead of the first digits displayed.

#1289405

Hello,

Since it is a custom codes problem, please provide a test site with the same problem, also point out where I can edit your custom PHP codes, I need to test it in a live website, thanks

#1290185

Thanks for the details, I can log into your website, will update here if there is anything found

#1290195

Here are what I found, in this website, your database is using $table_prefix "wp_pf_", so the old PHP codes won't work.

I have done below modification in your website:
Edit the your theme file "functions.php", replace the PHP codes as below:

function func_orderby_asking_price( $orderby ) {
	global $WP_Views, $table_prefix;
	
	 if($WP_Views->current_view == 907){
		 $orderby = str_replace( $table_prefix . 'postmeta.meta_value', "cast(replace(trim( leading '$'  from " . $table_prefix . "postmeta.meta_value),',','')  AS UNSIGNED)", $orderby );
	}
    return $orderby;
}
add_filter('posts_orderby', 'func_orderby_asking_price' );

Please test again, check if it is fixed, thanks

#1290469

My issue is resolved now. Thank you!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.