I am searching for a code, not a plugin, that will allow me to display the most popular tags based on post views for that day.

Someone asked this same question but they asked about a plugin, my points aren't high enough for me to comment and ask for a code, so I have to waste space and the same question :(


First thing we need to do is create a function that will detect post views count and store it as a custom field for each post. To do this, paste the following codes in your theme’s functions.php

> function wpb_set_post_views($postID) {
>     $count_key = 'wpb_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);
>     } } //To keep the count accurate, lets get rid of prefetching remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

Now that you have this function in place, we need to call this function on the single post pages. This way the function knows exactly which post gets the credit for the views. To do this, you would need to paste the following code inside your single post loop:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.