Viewing 2 replies - 16 through 17 (of 17 total)
  • Plugin Author dFactory

    (@dfactory)

    It’s not documented yet, but you can find it in includes/query.php.

    Apart from orderby post_views parameter there’s also “views_query” parameter, a bit similar to WordPress “date_query”. We’re using this for dashboard widget for example.

    You can use it in your WP_Query or get_posts() like this:

    'views_query' => array(
    	'year' => 2016,
    	'month' => 04,
    	'day' => 15
    )

    Year, month and day can be used altogether or separately. So you can get post views for specific year, month of given year or all post views from specific months or days in all years, etc.

    Additionally, whenever you make a query where post views are involved (with orderby or views_query parameter) the returned post objects include “post_views” along with other post data, like post_name, post_title etc.

    If you use WP_Query there there is also “total_views” returned for the given query, that holds a sum of all the views in the query.

    The “views_query” combined with the power of WP_Query can be used for achieving a lot of nice stuff, like trending posts for example (popular in a given date period) and many others.

    Thread Starter Beee

    (@beee)

    I noticed posts with 0 views are ignored, which kind of sucks because (for me) FAQ items with 0 posts are still to be shown.

    Any way around it ?

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘orderby post_views is not 'recognized' in pre_get_posts’ is closed to new replies.