admin管理员组文章数量:1331616
I have a code and can not use week or month filter for it. Please check the code and tell me how can I display popular post by week or months
<?php
$popularpost = new WP_Query(array(
'posts_per_page' => $cat,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
));
while ( $popularpost->have_posts() ) : $popularpost->the_post(); ?>
I have a code and can not use week or month filter for it. Please check the code and tell me how can I display popular post by week or months
<?php
$popularpost = new WP_Query(array(
'posts_per_page' => $cat,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
));
while ( $popularpost->have_posts() ) : $popularpost->the_post(); ?>
Share
Improve this question
asked Jul 25, 2020 at 12:42
m.javad koushkim.javad koushki
54 bronze badges
3
- What have you tried so far? What did you find when you searched for e.g. 'wordpress popular post for week and month' ? – mozboz Commented Jul 25, 2020 at 13:03
- 3rd party plugin support is offtopic here, you should ask at the plugins support routes – Tom J Nowell ♦ Commented Jul 25, 2020 at 13:05
- I want to do that without any plugin and with this code I just can display popular posts for all time not by week or month. – m.javad koushki Commented Jul 26, 2020 at 4:04
1 Answer
Reset to default 0Unless you're storing that data, you can't.
It looks like posts_views_count
is just a running total, so unless you've stored per month/week data, it simply does not exist.
What's more, you're storing that data in a post meta value, which has a lot of performance and accuracy problems. It's:
- incompatible with any form of page caching or CDN
- creates write queries on the frontend, slowing down your site and reducing how many people can visit at the same time
- extremely innacurate due to race conditions. The view counts will be lower than they actually are
If you want to do it properly, and have per month/week data, you'll need to use an external service such as Google Analytics, or a dedicated traffic software solution.
Otherwise, to make the plugin track per week and month, you will need to contact their support routes. 3rd party plugin support is offtopic here. If it does store that data, then you'll need to contact their support routes to ask how to access it.
本文标签: popular post for week and month
版权声明:本文标题:popular post for week and month 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742233251a2437609.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论