I have a custom admin column I want to make sortable.

All the functionality is in place, but when I sort I get this order:

enter image description here

I expect this to be in the order: 1.69, 1, 0.5

The code for the echo is:

        if ( 'my_col' !== $column_name ) {
        $field_data = get_post_meta($post_id, '_field_data', true);
        echo $increase_per_post;

I have tried intval, but those come out as 1 or 0

echo intval($field_data);
  • think simple :) I am giving you answer here. hope it will work echo number_format($field_data, 2, '.', ''); – Faysal Mahamud Apr 11 '17 at 18:41
  • Sorry - this still sorts in the original order in my question, the only change I can see is 0.5 becomes 0.50 and 1 becomes 1.00 – bigdaveygeorge Apr 11 '17 at 18:54
  • did you see this? it's helped me in the past: wpdreamer.com/2014/04/… – rudtek Apr 11 '17 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.