Crocoblock / suggestions

The suggestions for CrocoBlock project
194 stars 78 forks source link

Allow Query Generator or Smart Posts List element to display posts, ordered by post_views_count #78

Open BiglimeUK opened 5 years ago

BiglimeUK commented 5 years ago

Looking for support to list (blog) posts by its total amount of views, to allow us to make a query for a Most Popular posts panel - using the Smart Posts List element.

The out of the box example displays most popular, which only orders by defaults such as ID, title, comments etc. The panel does not display it ordered by meta_key post_views_count to order posts by the number of views it has had.

Thought this would work, but it doesn't:

{"post_type":"post","post_status":"publish","order":"DESC","orderby":"meta_value","meta_key":"post_views_count","posts_per_page":"5"}

Either use custom query support (above) or, because it is such a common order query, have it listed in the default post query dropdown alongside All, catagories, tags and id.

I am surprised this isn't covered in a tutorial or anywhere else online. Discussing it in the Facebook community has lead me here requested this much-overlooked feature as apparently this isn't supported.

Thanks.

MjHead commented 5 years ago

Hi @BiglimeUK. If meta field post_views_count contain number of post views you need to use meta_value_num as "orderby" value. Just one question - what plugin did you use to calculate posts views count, or is the some custom code?

BiglimeUK commented 5 years ago

Hi @MjHead Thanks, I tried this and it still didn't display posts by views.

I assumed because WP can give you a popular posts widget, this data would be used off the shelf using post_views_count?

Do I need to install a plugin to get this working then? I am not using anything to calculate post views, I assumed this was already recorded via WP because JetPack can provide this as a widget.

If you have any recommended plugins to do this, please let me know. Thanks.

MjHead commented 5 years ago

WordPress don't count post views from core. JetPack uses some custom functionality to calculate this values. You also need to use some 3rd party plugin to count posts views. For example - https://ru.wordpress.org/plugins/post-views-counter/

BiglimeUK commented 5 years ago

After looking into this more, I now notice how WP doesn't count post views, which is crazy. Having always installed jetpack I always thought it counted post views by default, as it allowed me to list the most popular posts with every WP install I did.

I have installed a post count plugin (https://wordpress.org/plugins/wordpress-popular-posts/), so it is now actively recording post counts, however, is it possible to use this data to format posts in a similar way to how jetpack fetches popular posts using the query generator?

What would the process be to hook into this? Is it possible or would we still need an update for the crocoblock plugin?

chaser32419 commented 3 years ago

For anyone with this issue here are some steps to get the most viewed posts.

https://sample-demos.xyz/blog/most-viewed-posts/