Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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';
        }
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #wp #post #view
ADD COMMENT
Topic
Name
5+4 =