Skip Navigation

[Resolved] Views orderby not accepting formats like 1:2.4

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

Problem:
When I order by a Custom Field that holds numeric values like 1:2.4 then the orderby fails.
It produces unexpected results.

Solution:
This is expected.
Numbers should be in a numeric format, like integer numbers or separated by an accepted delimitation like a dot.

This support ticket is created 6 years, 8 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 21 replies, has 4 voices.

Last updated by vijayB-4 6 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#559449

Hi Beda,

Many thanks for your response.
I have changed the datatype to single line. But the code given below is not getting converted. When I am using the post meta inspector i get the value as entered.

Can you please help

add_action('cred_save_data', 'msconvert', 10, 2);

function msconvert($post_id, $formdata){
if ($formdata['id']==11856 or $formdata['id']==11862)
{

$value = get_post_meta($post_id, 'wpcf-swim-time', true);
$keywords = preg_split("/:.]+/", $value);
$ms = $keywords[1] * 1000 + $keywords[0] * 60 * 1000 + $keywords[2] * 10;
wp_update_post(array('ID' => $post_id, 'swim_time' => $ms));
}
}

#560047

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

Beda is off today, he will be back to work tomorrow and takecare of this ticket.

Thank you

#560251

Well, that part of the Code is not using Toolset schemas, data or API.

It is entirely related to Custom PHP.
If it does not work with a Single Line, it will also not work with any other field type.

I cannot code that for you, I can, however, point you to the mechanisms that you need to use.

If you are still submitting values like 1:30,40, and so on, you need to get that data raw first.
This is done with the get_post_meta().
Once you have that value, you use PHP to remove the; and, signs.
This is done with str_replace().
hidden link

Then, after you replaced the; and, with "nothing" (str_replace("to_replace","with_what_to_replace","in_what_context");), you will have a raw numeric string.
This looks like 123456 instead of 12;34,56.

This value can then be calculated to seconds, if it represents milliseconds, by dividing it by 1000.
(as 1000 milliseconds, divided by 1000 is 1 second, right?).

Then you use update_post_meta() to create/update the real Post Field with this new value.

#560335

Hi Beda,

I think I have a solution

I have added a function to convert the string into a number
henace 03:12.31 gets stored as 192310. Hence it is numeric in nature

I have also created a shortcode to change the display at the front end.

Thank you very much for your assistance.

Now to the second part I need to do one thing

1. Get the best time of a swimmer in each race type i.e. personal best How can we go ahead on this?

The Credentials of my website are as sent before.

Vijay

#560703

Best Time, means lowest numerical value, right?

You will either create a View, and order the View by that field, and order it as ascending, return one result only.

That will show the lowest numerical value only, hence, the best time only.

To distinguish by type, which if I recall right is a Taxonomy, I recommend a Custom Filter by that taxonomy where the Visitor can filter by the type.
The result is still one and updated by the kind of race.

If this is not suitable, please open a new ticket, with one issue only given the new data you have now.
This will allow us to focus on the new topic environment correctly.

Thank you!

#561819

Hi Beda,
Will post a separate thread
Vijay

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