[Resuelto] Sort Column by Numerical Value using a single line field
This support ticket is created hace 3 años, 10 meses. 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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.
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.
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.
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.