WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
[resolved] How to change when "day" starts for post stats? (34 posts)

  1. jeremyers1
    Member
    Posted 2 years ago #

    I am sure this is simple, but I cannot figure it out...

    My "daily" post stats seem to start over at about 10:00 am or so. So at 9:30 am, it shows the popular posts for the previous 24 hours, but at 10:30, it only shows the popular posts for the last 30 minutes.

    How can I have the stats begin counting at midnight?

  2. jeremyers1
    Member
    Posted 2 years ago #

    Update:

    Not that it matters too much, but I was wrong about what time the plugin starts counting again. It is actually around 9:00 PM (Eastern).

  3. ridclubmba
    Member
    Posted 2 years ago #

    When does this plugin start to count visits? is it using calendar or it simply starts counting from the day it is installed?

    Example: visits this week are from Monday at 12 AM to Sunday 11:59 PM?

  4. jeremyers1
    Member
    Posted 2 years ago #

    I am thinking that it must start counting the second it is installed.

    I am going to test it tonight, and empty the cache and historical data at 11:59 pm, and see if that fixes it.

  5. Rick Radko
    Member
    Posted 2 years ago #

    It's more likely a time coversion issue. It's probably resetting at midnight GMT, which right now would be 8pm EDT.

  6. jeremyers1
    Member
    Posted 2 years ago #

    r3df,

    Yep. You are right. I emptied my cache last night at 11:59 pm, and it started counting again, but the day reset 10 minutes ago, at 8:00 PM EDT.

    So, where can I change the setting in the plugin to reset at midnight EDT?

  7. jeremyers1
    Member
    Posted 2 years ago #

    Could this bit of code be tweaked to fix this?

    This code is found in: wordpress-popular-posts/wordpress-popular-posts.php

    [Code moderated as per the Forum Rules. Please use the pastebin]

  8. Rick Radko
    Member
    Posted 2 years ago #

    @jeremyers1, I've not really had a chance to dig, (I've only just started using this plugin myself) but I don't think the plugin is the issue. I'd suspect it's the server time, probably is not set for eastern.

  9. jeremyers1
    Member
    Posted 2 years ago #

    r3df,

    You are probably right. It seems there should be a way to connect the plugin to the Blog Timezone settings instead, or even to the Blog's Site Stats. I just don't know enough php to figure it out.

  10. Rick Radko
    Member
    Posted 2 years ago #

    @jeremyers1, have you checked the times displayed beside the timezone setting in your dashboard under settings->general? Are they correct?

    Do you have access to your database cpanel/phpmyadmin?

  11. jeremyers1
    Member
    Posted 2 years ago #

    yes, I checked the times in Settings->general. Those are correct.

    Yes, I do have access to my databse phpmyadmin.

  12. Rick Radko
    Member
    Posted 2 years ago #

    Ok, lets see what time mysql thinks it is. Try entering: SELECT NOW() in the SQL box in myphpadmin and see what time you get.

  13. jeremyers1
    Member
    Posted 2 years ago #

    Ok, I tested it at 6:58PM Eastern (18:58)

    It came back 22:58:19, which is 10:58. So this is definitely the issue, since my daily stats reset at 8 PM Eastern.

  14. jeremyers1
    Member
    Posted 2 years ago #

    And now that you have discovered the problem, I was able to set the proper time.

    I used this in the SQL box:

    SET time_zone = 'America/New_York';

  15. jeremyers1
    Member
    Posted 2 years ago #

    Oh, and for any not in the Eastern Timezone, I think that if you don't know your named timezone, you can use a UTC offset, such as this:

    SET time_zone = '-5:00';

    if you don't know your UTC offset, just search Google for it.

  16. Rick Radko
    Member
    Posted 2 years ago #

    The best solution would be to ask your hosting provider to fix it on the server.

    Did the set work? Try select now() again afterwards, it should be back at it's old time. The set does not stick for me, which as as per the docs as I understand it. The SET time_zone is a per session setting, and unfortunately in php/web, an sql session is usually per page load.

    You'll need to put something like:
    $wpdb->query("SET time_zone = 'America/New_York'");
    in either this plugin, or your functions.php to set it every time a page loads. (depending on where you put it, you may need: global $wpdb; before it too.)

  17. Rick Radko
    Member
    Posted 2 years ago #

    Thinking a bit more, where is your server? If it's not local then you probably won't be able to get them to change the time.

  18. jeremyers1
    Member
    Posted 2 years ago #

    You were right again. It did not permanently change the timezone. Oh well.

    How does WordPress put the right time in for the posts and comments? These also are saved in the Database. Couldn't the plugin call that time (in the settings) rather than the one in the Database?

  19. Rick Radko
    Member
    Posted 2 years ago #

    If the times are right for WordPress then it is probably using php times to create strings/data to save in the database and not SQL. This plugin is using both php time functions and sql time functions, CURDATE() is an sql one, to mange time strings.

    To get it fixed, you either need to get it changed on the server, which may not be possible, or add it to the plugin as above with a php call to the DB that fixes it every time a page loads.

  20. Rick Radko
    Member
    Posted 2 years ago #

    Oh, to answer your last question, yes the plugin could just use php time, but that's not the way it was written. It looks like the author used the SQL functions to try to take advantage of those functions instead of doing the work in php. In this case one might consider this a design flaw, as not everyone has a server in the timezone that they want their website to be.

  21. Rick Radko
    Member
    Posted 2 years ago #

    Hmm, been looking at this a bit more, not sure messing with the SQL time_zone is the right answer, it's probably safe, but depending on how/where you make the change, you are potentially affecting other calls to the DB in WordPress. Have a prototype with no SQL time calls. Still needs a bit of testing. Do you have test install, or just your live sites?

  22. jeremyers1
    Member
    Posted 2 years ago #

    Just live sites. I'm probably just going to ignore it for now.

  23. Rick Radko
    Member
    Posted 2 years ago #

    Just curious, why are you using the daily option? Would a rolling 24hours be better instead of having the reset?

  24. jeremyers1
    Member
    Posted 2 years ago #

    Sure. I wouldn't mind using a rolling 24 hours. The plugin doesn't seem to have this option. Is there a plugin that does?

  25. Héctor Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    Hi guys,

    Just took a quick read to the conversation and I probably need to re-think this. It's been a long time since I last took a look into my code so it might take a while to re-learn it and make some improvements.

    This issue has already been noted down on my TODO list. If any of you have any further suggestions about this please let me know.

  26. Rick Radko
    Member
    Posted 2 years ago #

    @Héctor, a timely re-appearance! I was contemplating forking the plugin as it had not been supported for over a year and needed some updating. I've patched this time issue using WordPress config based time, and I have another bug patch for a qTranslate issue where the content for the widget display is not language filtered.

    I can send you the patches if you'd like.

  27. Rick Radko
    Member
    Posted 2 years ago #

    @jeremyers1, no there are not many alternatives to this plugin, which is why I'm using it despite no support for a year, and why I was considering forking it. I was thinking of changing it to have the last 24 hours instead of "today".

  28. Héctor Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    Sure r3, all contributions to make WPP a better plugin are welcome!

    Please send your patches to hcabrerab at gmail. If you add comments to the changes you've made to my plugin I'd be more than grateful.

    There is, however, some more fixing to do so I won't be pushing an update soon. Maybe you want to share the patches here so others can use it until WPP gets updated (probably no more than two weeks, hopefully sooner than that).

    Thank you in advance for your help! I'm sure everyone using this plugin will appreciate it as much as I do now.

  29. jeremyers1
    Member
    Posted 2 years ago #

    r3df,
    I would love those patches, if you want to make them available. I think the rolling 24 hour option would be great.

  30. Rick Radko
    Member
    Posted 2 years ago #

    @jeremyers1, I didn't do the 24hrs, was just planning it. It's a bit of a change for the plugin, more data needs to be saved in the DB and managed and tidied. I just fixed the time issue.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic