• Resolved newharvest

    (@newharvest)


    Hi,

    I’m working on creating a RSS feed that incorporates My Calendar events in with regular WordPress posts. My results were sorting incorrectly, and I finally figured out why. I think it is a bug in My Calendar, so I thought I’d let you know.

    Using the get_post_time() function, depending on whether or not the $gmt argument is set, mc-events return two wildly different values.

    Relevant codex page: https://codex.wordpress.org/Template_Tags/get_post_time

    Expected Behavior:
    The results of calling get_post_time($format, $gmt) should differ by $gmt_offset (whatever is set in WordPress). In our case, this is -7 hours. get_post_time($format, true) should return a datetime 7 hours ahead of get_post_time($format, false).

    Actual Behavior:
    The results of calling get_post_time() differ by more than five days.

    Example:

    Code (I know, not valid XML tags but just for testing/debugging purposes):

    <postTimeTrue>'.get_post_time('D, d M Y H:i:s +0000', true).'</postTimeTrue>
    <postTimeFals>'.get_post_time('D, d M Y H:i:s +0000', false).'</postTimeFals>

    Result:

    <postTimeTrue>Tue, 20 Feb 2018 10:20:18 +0000</postTimeTrue>
    <postTimeFals>Sun, 25 Feb 2018 11:22:28 +0000</postTimeFals>

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter newharvest

    (@newharvest)

    After some further investigation, it seems that post_date column in the database is being updated when the post is modified, which should not be the case. When a post is updated, post_modified should be updated. post_date should contain the date the post was originally published.

    post_date_gmt is not being updated when the post is modified, which explains why I was getting the proper date to display in the feed from the start, but the posts were sorting incorrectly (it displays the GMT value but sorts by the regular post_date value).

    • This reply was modified 6 years, 1 month ago by newharvest.
    • This reply was modified 6 years, 1 month ago by newharvest.
    Plugin Author Joe Dolson

    (@joedolson)

    Thanks for catching that – since My Calendar doesn’t use the post date of the posts it creates, it’s unlikely I would have caught that in normal usage. It should be fixed in the next release.

    That said, the next release is a major release, and if you’re doing any substantive custom coding, I suggest testing with the beta. It’s available now from https://wordpress.org/plugins/my-calendar/advanced/

    Thread Starter newharvest

    (@newharvest)

    Thanks Joe!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_post_time() of mc-events gives incorrect value’ is closed to new replies.