I need to use 7 days post sorting options in the theme. But 7 days post view counting is incorrect and showing some totally incorreect numbers like: 1699662509 where total view are around 1000.
I know that I can manually change this, but it is impossible to go and do that on every post where I have my website posting from year 2010.
On some posts I cant even see those custom fields to be able to edit them, I wanted to manually change some posts views so it is at least showing post I want to, not some random from few years before.
I have turned on option for AJAX VIEW COUNT and USE LAST 24/48 HOURS & 7 DAYS POST SORTING.
And, I know it is already discussed before (I found people asking for this option from 5-6 years ago), but pls add option to display and sort popular posts that are published only in last 7 days. I think it is much simpler soulution than this one we have now. You would need only one custom field “post_views” and in the module or block we should be able to filter posts published from 7 days before or maybe leave as option to enter number of days manually. Our database would be smaller and less busy, server too.
Sorry, I added wrong link above for the screenshot where I cant see custom fields showing post views for 7 days count
No post views 7 day custom field
-
This reply was modified 2 years by
bhcrow.
Hello @bhcrow !
This number: https://prnt.sc/zHOkdZ6oXyft is a timestamp of the last date on which the posts views were updated for that article.
Unfortunately, this is the way our feature works now. We will take into consideration your query in the future!
Thank you so much for your understanding!
I saw here on the forum a lot of users asking for same thing. I think right now this is too complicated. For it to run properly you have to turn on:
– option in theme panel to show views on post
– 24h/48h post views sorting
– ajax view count
– insert the element for single post views inside template for single post
– hide with css showing views on frontend.
And we all know that this uses a lot of server resources to be implemented and if you didnt do this all properly this option is not working. These days to have Popular posts block on your website is MUST.
With the options I proposed everything would be much simpler. Post views in backend are working even without all options turned on. If we can just use that with filter to show only posts published 7 days ago.
-
This reply was modified 2 years by
bhcrow.
Let’s see the case more closely as popular posts is vital nowadays
I have all below set:
– option in theme panel to show views on post
– 24h/48h post views sorting
– ajax view count
– single post views inside template for single post
I made a post today:
From google analytics i see it has about 1600 views
From special post fields:
post_views_count has 1660 and it is correct
post_views_last_24_hours, post_views_last_48_hours and post_views_count_7_day_total show all 77 views, the fact that all 3 have the same number is correct as post is from today but why are so different and wrong comparing to post_views_count ?
All these 4 fields obviously should show the same number as post is today’s, right?
post_views_count_7_day_last_date has 1703030789, is it a timestamp or something?
Thanks!
I had similar problem with my website with this popular posts. I solved it in a way that I made custom shortcode for sorting based on total number of views (not in last 7 days or 48h). In shortcode you have the option to choose how old you want your posts to be. hat means that it wont show posts older than 7 days (or any other number of days defined in shortcode) even though if they are visited.
Here is my codes which works for me in my Newspaper child theme. Use it freely if it suits you and your website.
Code in functions.php file in child theme:
// Include the popular posts shortcode file
include_once get_stylesheet_directory() . '/sedamdana-popular-shortcode.php';
File in child theme whic I named “sedamdana-popular-shortcode.php”
(this forum is not allowing me to share code from my php file, so I uploaded it on link: https://file.io/PSWL4VdNb7xN)
The shortcode output is styled using CSS defined in the PHP code. You can further customize the styles by modifying the CSS within the bhcrow_posts_shortcode_styles function.
Once the PHP code is added, you can use the [bhcrow_posts] shortcode in your posts, pages, or widgets where you want to display the list of posts.
Example usage: [bhcrow_posts title=”Popular Posts” number=3 days=30 category=”technology” sort=”visits” show_date=false]
Customize the shortcode attributes as per your requirements. For example, you can change the number of posts displayed, the sorting criteria, or whether to show thumbnails or dates.
The shortcode [bhcrow_posts] can accept several attributes to customize its behavior. Here are the available attributes and their default values:
title (default: ‘Posts’): The title of the section.
number (default: 5): The number of posts to display.
days (default: 7): Number of days to consider for displaying posts.
category (default: none): The category of posts to display.
show_thumbnails (default: true): Whether to show post thumbnails.
show_date (default: true): Whether to show post dates.
show_visits (default: true): Whether to show visit counts.
show_category (default: true): Whether to show post categories.
show_title (default: true): Whether to show post titles.
sort (default: ‘visits’): Sorting criteria for posts (‘visits’ for popularity, ‘latest’ for latest posts).
title_limit (default: none): Character limit for post titles.
cache_duration (default: 60): Cache duration in minutes.
The final output is cached using set_transient to improve performance by avoiding repeated database queries.
After adding the shortcode to a post or page, view the page on your website to see the output. The posts should be displayed based on the attributes you’ve specified in the shortcode.
Remember to backup your files before making any changes, especially when editing theme files or using any PHP code.
I use it without any issues on my website Visoko.co.ba news portal
Here is the screenshot of it. I use it with minimum options on my homepage.
-
This reply was modified 2 years by
bhcrow.
these numbers for 24h, 48h and 7d didnt work for me at all. Often I see some posts in popular section which were too old to be there, that is why I made my own shortcode and limited displayed posts to show only ones published in last 7 days.
Also with this code there is no need for all those addtional numbers to be stored in database, so I think it helps perfomrance too
Hello @depatech !
It’s on our investigation list. All the fixes will appear in the changelog: https://tagdiv.com/newspaper/
Thank you!
Hello!
Our developer investigated this feature, and obviously there is no other bug with it in the latest update of the theme. It is much more sensible if you have or still use a cache plugin. Unfortunately, you can’t collect the old post views. Sorry! That’s why could be some differences between the default meta and our custom meta used for this feature.
Thank you so much for understanding!
Hi Bettina, thanks for update!
No problem for old data, actually it seems all want to have
popular in a latest timeframe.
When use popular 48h for example, block will present
only posts from last 2 days or posts that have the most views
last 2 days but can be from last year fo example?
Also i noticed that caching from tagdiv composer such blocks does not work,
i set 30 minutes cache but i see at brosing that posts at block change inside the 30 minutes
I am using W3 Total cache. The script I am using is still in use on my website with 3 different settings (newest, popular and featured category) without any issues until now.
Here is the new link to the file:
https://file.io/XMUi2BDrmu6k
