Wordpress - 通过没有插件的视图获得 5 个热门帖子 [英] Wordpress - get 5 popular posts by views without plugin
本文介绍了Wordpress - 通过没有插件的视图获得 5 个热门帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有包含帖子图像的自定义字段,我想显示按视图排序的前 5 个帖子.我正在使用 WordPress,你能帮我吗?
I have custom fields with image from posts, and I want to display the top 5 posts sorting by views. I am using WordPress, can you help me please?
抱歉我的英语不好.
谢谢.
推荐答案
它运行的查询按字母顺序(1、2、20、23、3、4 等)返回帖子
The query it runs returns posts in alphabetical order (1, 2, 20, 23, 3, 4, etc)
你只需要改变
'orderby' => 'wpb_post_views_count'
到
'orderby' => 'meta_value_num'
对于前 5 名,使用:
For the top 5, use:
$popularpost = new WP_Query(array(
'posts_per_page' => 5,
'meta_key' => 'wpb_post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
));
这篇关于Wordpress - 通过没有插件的视图获得 5 个热门帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文