WordPress rating by views [closed]

First of all you have to start log views of each post. You can do it by yourself or by a plugin. Here you have an example how you can track this number without any plugin.

Add this code to the theme’s functions.php file

function prefix_get_post_views( $post_id ){
    $count_key = 'post_views_count';
    $count = get_post_meta( $post_id, $count_key, true );
    if( '' == $count ){
        update_post_meta( $post_id, $count_key, 0 );
        return 0;
    }
    return $count;
}

function prefix_set_post_views( $post_id ) {
    $count_key = 'post_views_count';
    $count = get_post_meta( $post_id, $count_key, true );
    if( '' == $count ){
        update_post_meta( $post_id, $count_key, 0 );
        return 0;
    }
    $count++;
    update_post_meta( $post_id, $count_key, $count );
}

// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );

Further you have to add the code below to your single.php or single-{your-post-type}.php files. You can add the code only to the one single-_.php file of that post type which you want to show the HOT sign.

<?php
    prefix_set_post_views( get_the_ID() );
?>

Now you’re tracking your views! But it’s showing nowhere. So let’s show it!

You’ve to find out the right theme’s file and place where are the posts echoing and put there this code.

<?php if( prefix_get_post_views( get_the_ID() ) >= 1000 ) : ?>
    <span class="hot-sign">HOT</span>
<?php endif; ?>

Note that the ‘prefix_’ should be replaced by your own theme prefix.

Inspired by: http://wpsnipp.com/index.php/functions-php/track-post-views-without-a-plugin-using-post-meta/