Answers for "wp post view"

PHP
0

wp post view

function bac_PostViews($post_ID) {

    $count_key = 'post_views_count';
    $count = get_post_meta($post_ID, $count_key, true);

    if($count == ''){
        $count = 0;
        delete_post_meta($post_ID, $count_key);
        add_post_meta($post_ID, $count_key, '0');
        return $count . ' Visitas';

    }else{
        $count++; 
        update_post_meta($post_ID, $count_key, $count);

        if($count == '1'){
        return $count . ' Visita';
        }
        else {
        return $count . ' Visitas';
        }
    }
}
Posted by: Guest on September-14-2021

Browse Popular Code Answers by Language