Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #54512
    wpraider
    Participant

    Hello,

    How Can I query the most viewed posts, with a specific tag, by a specific year, lets say 2021?

    I dont want the most viewed posts that have been published in 2021, but the most viewed posts from year 2021 with any published date.

    I can see in the database that every post has a view count for every year. How can I query that?

    Can I do this with pvc_get_views()?
    Could you give me an example pvc_get_views() query?

    If this cannot be done with pvc_get_views(), then could you very roughly describe how the mysql query should look like to sort posts of a specific tag by post views of a specific year?

    I hope I am not asking for too much.

    thx

    #54514
    wpraider
    Participant

    Found it in the source code.

    You can just add a views_query to the wp_query args, like:

    // required by PVC
    ‘suppress_filters’ => false,
    ‘orderby’ => ‘post_views’,
    ‘fields’ => ”,
    ‘views_query’ => array(
    ‘year’ => date(‘Y’)
    )

    the views_query options are:
    ‘views_query’ => array(
    ‘year’ => ”,
    ‘month’ => ”,
    ‘week’ => ”,
    ‘day’ => ”,
    ‘after’ => ”, // can be string or array
    ‘before’ => ”, // can be string or array
    }

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.