0

I have this function in a wordpress theme :

// function to count views.
function setPostViews_anthemes($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}    

I need that the number of viws show a random number from 1 to 999

wpclevel
  • 2,451
  • 3
  • 14
  • 33
Faouzi.A
  • 11
  • 2

1 Answers1

1

To generate a random integer from 1 to 999 in PHP use rand(1,999)

// function to count views.
function setPostViews_anthemes($postID) {
    $count_key = 'post_views_count';
    $count = rand(1,999);   
    update_post_meta($postID, $count_key, $count);
}
user2314737
  • 27,088
  • 20
  • 102
  • 114