How to make Fake Views on WordPress

Use something like this : (add it in your function.php) and load your site once. after it finish, deactivate the function. (don’t forget to declare your $postID) function my_update_posts() { $count_key = ‘post_views_count’; $args = array( ‘post_type’ => ‘post’, ‘numberposts’ => -1 ); $myposts = get_posts($args); foreach ($myposts as $mypost){ $mypost->post_title = $mypost->post_title.”; $count = … Read more

Post rank by views

Is there any specific reason you are using $wpdb? You can do the same with WP_Query which is always recommended. So if your meta key for counting post views is views then you can run this WP_Query to return top viewed posts. You can also limit results by posts_per_page. <?php $args = array( ‘post_type’ => … Read more

Updating post_views_count on publish [duplicate]

So this is the code I earlier posted. // Create custom field on post publish function wpse_custom_field_on_publish( $new, $old, $post ) { if ( $new == ‘publish’ && $old != ‘publish’ && !get_post_meta( $post->ID, ‘post_views_count’, true ) ) { add_post_meta( $post->ID, ‘post_views’, rand(829, 1013), true ); } } add_action( ‘transition_post_status’, ‘wpse_custom_field_on_publish’, 10, 3 ); Let … Read more

Display (custom) post number of views

This is a repurposed post from another question which the OP did not find useful, so I’m reposting it here and hopefully will be useful here Please modify the code as needed. Here is a post I have recently done on stackoverflow. It is a modified version of the code you are using. I had … Read more

How can I create the number of custom post views

add this in your functions.php function getPostViews($postID){ $count_key = ‘post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, ‘0’); return “0 View”; } return $count; } function setPostViews($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); } }

Showing “0” pageview when there is no view

You can optimize your code a bit and localize it. I would add the results from get_post_meta() to a variable and then check the returned result an act upon that You can try something like this <div class=”mypageview”> <?php $views = get_post_meta( $post->ID, ‘pageview’, true ); if ( !$views ) _e( ‘0 post views’ ); … Read more