0
votes

I have been receiving the following errors for some time:

PHP Warning:  A non-numeric value encountered in /home/user/public_html/wp-content/themes/mytheme/content-one.php on line 29
PHP Warning:  A non-numeric value encountered in /home/user/public_html/wp-content/themes/mytheme/content-one.php on line 30

Those lines are:

$minutes = floor($duration_in_seconds / 60);
$seconds = $duration_in_seconds % 60;

PHP Version: 7.3.20

Can anyone help me with some advice, how to fix this issue? Thank you!

1
It seems $duration_in_seconds doesn't contain a numeric value, therefore the math operations are failing. I'd suggest you print their values to see what is going on. - dbaltor
Everything look fine. I can't figure out where I'm wrong. $duration_in_seconds = get_post_meta($post->ID, 'duration', true); $minutes = floor($duration_in_seconds / 60); $seconds = $duration_in_seconds % 60; echo $minutes . ":" . str_pad($seconds, 2, "0", STR_PAD_LEFT); - user2151960

1 Answers

0
votes

$duration_in_seconds might be a string, a simple way to fix it is to do something like:

$duration_in_seconds = intval($duration_in_seconds, 10)