Skip Navigation

[Resolved] Sort Column by Numerical Value using a single line field

This support ticket is created 4 years, 10 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 6 replies, has 2 voices.

Last updated by marcusC-4 4 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1486015
image001.png

We have created a table that displays the number of "likes" that our content has. The "Like" field is a custom field created with Toolset and it's a single line field type. It has to be a single line and cannot be changed to a number field.

Is it possible to sort our table numerically even though this is a single line field?

You can see the table here: hidden link

And with the link I gave, you should see that the table is sorted by the 2nd column but it isn't in order. I've also attached a screenshot that shows how it is display for me.

Thanks,

Marcus

#1486523

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Marcus

I can see that the sorting isn't working for that Likes column, but I can't see why from the front end, can I get access to your site to take a closer look?

I'm afraid, though, that if this is a string field it will be sorted as a string, there isn't an option to change how it is sorted. It would need to be a number field to be sorted as a number.

I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site.

#1486827

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2020-01-30 at 13.34.29.png

Hi Marcus

When I check the curricula posts I see that they don't have a value stored for the Likes field, they have a custom shortcode (see screenshot).

Because the value stored in the database for the field is "[rating]" then when the table is sorted by that column, which happens with a new database query which specifies that field for the sort order, it fails because, well, there are no numbers to sort by.

What you are trying here cannot work.

#1486897

Makes sense.

Is there a way to create a "Like" field like we're trying to do using Tooslet?

#1488223

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I'm not sure what your current solution is, but it needs to save a value in the postmeta table if you are to be able to order by it.

I know other clients have used the plugin Favorites (hidden link) which may require a little effort to integrate with Toolset, but I know it saves the favorite count in post meta as "simplefavorites_count" so you can output that in your View listing posts and it should work in your table sort.

#1488805

Ok, thanks for the info & the suggestion. We'll look into it.

#1488807

My issue is resolved now. Thank you!