I'm having a hard time using this snippet I'm getting double views each time the post is queried. This is in my functions.php file: 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"; } 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); } } // Remove issues with prefetching adding extra …
I need to create most viewed post column in the template file, but based on post view count? Function File function wpb_get_post_views($postID){ $count_key = 'wpb_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.' Views'; } Template File <?php $popularpost = new WP_Query( array( 'posts_per_page' => 4, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); while ( $popularpost->have_posts() ) : $popularpost->the_post(); the_title(); endwhile; ?>
Is there any way to display total views of all posts of one category? How to show that number on archive page? I have used this code to count views of each post: function getPostViews($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'); return"0 Views"; } return $count.' Views';}function setPostViews($postID){ $count_key ='post_views_count'; $count = get_post_meta($postID, $count_key,true); if($count=='' || $count < 0){ $count =0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key,'0'); }else{ $count = $count + 1; …
I need to reset the post views count of a web site. Currently Im using this on my 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.' Views'; } 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); } } add_filter('manage_posts_columns', 'posts_column_views'); add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2); function posts_column_views($defaults){ $defaults['post_views'] = __('Views'); return …
I have 1 essential questions I want to count the total views of all posts published by a user (login user). for example show: total view of your all posts: 485 Is there a way to do this? Can you help me?
I'm using wp-postviews to track views for posts by authors on my site. It stores the view count in the post meta field $views. I'd want to show on their profile a total count of views for all their posts combined. How to do that?
I tweaked the default behavior of the post listing page (for a custom post type) via pre_get_posts, the thing is that now the count of All | Mine | Published isn't the right one. I'm aware there is this filter: views_edit-{post_type} But we are editing the HTML output, so to correct this value i'm currently doing : $views['all'] = preg_replace("/\(\d+\)/", "($new_count)", $views['all']); Which I find it dirty, I'm aware of the filter wp_count_posts which return this: stdClass Object ( [publish] …
I'm tweaking default's wordpress permissions by adding my own via the capability_type and map_meta_cap in register_post_type(), but I noticed that as soon I add the capability_type argument, the default view when I click on View Posts is set to mine. register_post_type( 'devis', array( [...] 'capability_type' => array('devis', 'deviss'), // Without this line, All posts is the default view [...] ) ); I found how to solved this "problem" with this post: Make the 'all' filter default instead of 'mine' in …
I need to hide/remove the numbers behind the Edit screen in the backend. All (30) | Published (22) | Draft (5) | Pending (2) | Trash (1) As I am running a multi author blog and each author has just access to its own posts, I dont want to publish the cumulated information of all authors. With the following code the views are completely unset, but I dont want to remove the whole functionality: function remove__views( $views ) { unset($views['all']); …
Is there a way to show a PDF file inside Post in Wordpress? I used the tag but if someone has Internet Download Manager the Dialog will appear to Download the PDF file and then if they click cancel they will not be able to see it, they can ONLY download it Is there's a way to stop automatic download? There are many plugins for that but the image quality is too bad.
I wanted to know if i can change the way i display views count in WordPress. Example: 1000 views = 1k - 10000 views = 10k I'm counting and viewing post views by using this code: // Count views 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); } } // Show views function getPostViews($postID) { $count_key = 'post_views_count'; $count = …
I'm trying to show the top 5 most popular ( most viewed ) blogs. It is working as it should and then I added a script in the functions.php to display the views just while I build this so I can see it's working. The problem is when I click a post, they all +1 in views, even tho they are ordering my most viewed to least viewed as they should, they are still connected to each other. How do …
I am using the below code to display post views. How can I get the data for every day, week and month? function gt_get_post_view() { $count = get_post_meta( get_the_ID(), 'post_views_count', true ); return "$count views"; } function gt_set_post_view() { $key = 'post_views_count'; $post_id = get_the_ID(); $count = (int) get_post_meta( $post_id, $key, true ); $count++; update_post_meta( $post_id, $key, $count ); } function gt_posts_column_views( $columns ) { $columns['post_views'] = 'Views'; return $columns; } function gt_posts_custom_column_views( $column ) { if ( $column === …
I use a post views counter to save post views - function calculatePostViews($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, '1'); return; } $count++; update_post_meta($postID, $count_key, $count); return; } The issue is, everytime the post page is refreshed manually, the view increments by 1. I need to check this. How ?
I have decide to use WordPress as a CMS to my 5 moths old website. I have already added all previous posts to my new site ( WordPress ). But now I need to change view counts to previous views counts. I can't find hit_count or views_count from PhpMyAdmin database. How to change views count number manually on WordPress? Please help. function.php <?php // function to display number of posts. function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); …
Example: [shortcode id=""]. I just want to how to dynamically fetch each post ID on Posts Lists page over archive page or normal posts page inside the shortcode placed in excerpt. Currently I'm using Post Views plugin. Using its shortcode [post-views], I'm able to correctly display post view on each single post page. However I'm facing issue when I include the same shortcode in Excerpt to show it over Posts List Page and Archive List page. There it appears Zero. …
I dont know how to code and sorry for my bad english, so i found a code here to make a random views on my post views using $count = rand(700,999); which make a random views for my post but the problem is everytime a user click a post views changes again and not update the meta data. function ktz_setPostViews($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 1; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; …
I'm trying to get the top 10 users in (specific roles) by the highest post views, but this code makes the site loading time too big, and I don't know why! I'm highly appreciated your help. <?php global $wp_query; $topuser = array(); $args = array( 'role__in' => array('contributor', 'author') ); $user_query = new WP_User_Query( $args ); $users = $user_query->get_results(); foreach ( $users as $userss ) { $counter = 0; $args = array( 'date_query' => array( array( 'after' => '1 week …