Custom plugin wp

0

I have the following code

function app_searched_today_visitbh() {
    global $wpdb;
    $horas = $wpdb->get_var("SELECT time_format(timediff(now(),date_people),'%i%h') FROM today_people LIMIT 1"); 
    return ("<span id='days_since'>$horas</span>");
}

add_shortcode('appsearchedtodayvisitbh', 'app_searched_today_visitbh'); 

Its operation is as follows, add the result of DATE in a span consulting the database, in a table today_people with a column date_people of DATETIME format,

UPDATE

This code is a bit old, what I really need, is that it is like a visit counter but manual, that I leave the number 5, and start every minute to increase. No need for cookies or localstorage.

Thank you very much! I'm waiting for your help!

    
asked by Juan David 14.02.2017 в 05:30
source

1 answer

0

I understand that what you want is to take out of the hours, the days. I have a code in PHP that given the difference in milliseconds, it takes you hours, minutes and seconds.

public function humanTime($milisegundos)
{
    $horas = (int) (($milisegundos / (1000*60*60)) % 24);
    $minutos = (int) (($milisegundos / (1000*60)) % 60);
    $segundos = (float) (($milisegundos % (1000*60*60)) % (1000*60)) / 1000;
    $tiempo ='';

    if ($horas > 0) {
        $tiempo = "{$tiempo}{$horas} h";
    }

    if ($minutos > 0) {
        $tiempo = "{$tiempo} {$minutos} min";
    }

    if ($segundos > 0) {
        $tiempo = "{$tiempo} {$segundos} seg";
    }

    return $tiempo;
}

Modifying it a bit, you can take out the days, hours, minutes and seconds, which I understand is what you want.

If so, tell me, and you can modify it for it.

    
answered by 15.02.2017 в 09:09