Answers.Body: <p>The <a href="https://github.com/putyourlightson/craft-entry-count" rel="nofollow noreferrer">Entry Count plugin</a> does not record the individual times at which each entry was counted, therefore there is no way to filter by a specific time period. For that you'll need to find another solution. </p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>As you've requested it in the comments, the only way to get this to work without the existing plugin would be to reset all entry counts once a day using a cron job. For sure not ideal but it would require a minimal amount of code refactoring. </p>
  
  <p>To set this up you would need to add an anonymous controller method (that requires a key to be accessed) to reset all entry counts:</p>
  
  <pre><code>public function actionResetAll()
  {
      // verify query parameter key
      if (craft()-&gt;request-&gt;getParam('key') != 'xyzxyzxyzxyzxyzxyz') {
          die('Unauthorised key');
      }
  
      craft()-&gt;entryCount-&gt;resetAll();
  }
  </code></pre>
  
  <p>As well as a service method to do the work:</p>
  
  <pre><code>public function resetAll()
  {
      // delete all records from DB
      EntryCountRecord::model()-&gt;deleteAll();
  
      // log reset
      EntryCountPlugin::log('All entry counts reset.');
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-22T19:35:40.580Z
Answers.Text: Considering it is the course example, Ben - would it be possible (for students) to add this feature or the EntryModel to the plugin?
Answers.UserDisplayName: Nutmeg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-23T07:42:52.363Z
Answers.Text: Sure, although it would require quite a bit of code refactoring.
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-30T15:59:04.430Z
Answers.Text: I'm working on this again, is there any other way to get this done? Of are you working on it already @BenCroker?
Answers.UserDisplayName: Jan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-04T08:24:41.150Z
Answers.Text: Have added an update to my answer along with some code samples. Beyond this you're going to essentially have to write some code :)
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-22T14:13:03.763Z
Answers.LastActivityDate: 2016-12-04T08:23:09.927Z
Answers.LastEditDate: 2016-12-04T08:23:09.927Z
Answers.UserDisplayName: Ben Croker
Body: <p>I'm trying to get the most popular entries of my site in a certain time period, for example 24h, based on the amount of views (clicks) it gets. I'm using the entry count plugin to do the counting but I can't get it working like I want. It can get a most viewed of all time array, but I need a most viewed of the last 24h.
  I've followed the course that the plugin is based on, but I only get errors when trying to customize it...
  Can anyone help me out? Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-22T04:16:20.590Z
Comments.Text: Hi Jan, I am sure native Twig can help out here. Can you show the code you are working with?
Comments.UserDisplayName: Nutmeg
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-22T07:59:42.727Z
Comments.Text: Hi Nutmeg,
  Using the entry count plugin I call the "counted' entries like so: 
  `{% set countedEntries = craft.entryCount.entries %}`
  and this is the first problem, I can't seem to get them ordered by any way possible except by count number (tried by title, dateCreated, dateUpdated, id). So that's the first hurdle I need to pass. Once that's done, I need to calculate the amount that an article has been viewed in the last 30h, and sort the articles by that amount, setting a limit of 10
Comments.UserDisplayName: Jan
Tags: <plugin-development><entries><plugins><count>
Title: Entry Count plugin
ThreadText: # Entry Count plugin
  
  (Asked by: username_0 on 2016-11-21)
  
  I'm trying to get the most popular entries of my site in a certain time period, for example 24h, based on the amount of views (clicks) it gets. I'm using the entry count plugin to do the counting but I can't get it working like I want. It can get a most viewed of all time array, but I need a most viewed of the last 24h.
  I've followed the course that the plugin is based on, but I only get errors when trying to customize it...
  Can anyone help me out? Thanks!
  
  **Tags:** plugin-development, entries, plugins, count
  
  > **Comments:**
  > **username_1**: Hi Jan, I am sure native Twig can help out here. Can you show the code you are working with?  
  > **username_0**: Hi username_1, Using the entry count plugin I call the "counted' entries like so:  `{% set countedEntries = craft.entryCount.entries %}` and this is the first problem, I can't seem to get them ordered by any way possible except by count number (tried by title, dateCreated, dateUpdated, id). So that's the first hurdle I need to pass. Once that's done, I need to calculate the amount that an article has been viewed in the last 30h, and sort the articles by that amount, setting a limit of 10  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-11-22. Score: 2
  
  The [Entry Count plugin](https://github.com/putyourlightson/craft-entry-count) does not record the individual times at which each entry was counted, therefore there is no way to filter by a specific time period. For that you'll need to find another solution.
  
  **UPDATE:**
  
  As you've requested it in the comments, the only way to get this to work without the existing plugin would be to reset all entry counts once a day using a cron job. For sure not ideal but it would require a minimal amount of code refactoring.
  
  To set this up you would need to add an anonymous controller method (that requires a key to be accessed) to reset all entry counts:
  
  ```
  public function actionResetAll()
  {
      // verify query parameter key
      if (craft()->request->getParam('key') != 'xyzxyzxyzxyzxyzxyz') {
          die('Unauthorised key');
      }
  
      craft()->entryCount->resetAll();
  }
  
  ```
  
  As well as a service method to do the work:
  
  ```
  public function resetAll()
  {
      // delete all records from DB
      EntryCountRecord::model()->deleteAll();
  
      // log reset
      EntryCountPlugin::log('All entry counts reset.');
  }
  
  ```
  
  > **Comments:**
  > **username_1**: Considering it is the course example, Ben - would it be possible (for students) to add this feature or the EntryModel to the plugin?  
  > **username_2**: Sure, although it would require quite a bit of code refactoring.  
  > **username_0**: I'm working on this again, is there any other way to get this done? Of are you working on it already @username_2?  
  > **username_2**: Have added an update to my answer along with some code samples. Beyond this you're going to essentially have to write some code :)  
  
  ---
  
  