• Resolved Peter_L

    (@peter_l)


    I’m working on a 10 years old self hosted WP install. I was looking into changing the published date into the modified data for all blog posts. In the templates, I replaced the code. Old one:
    <time datetime="<?php the_time('c');?>"> <?php the_time('j F Y'); ?></time>

    new one:
    <time datetime="<?php the_modified_time('c');?>"><?php the_modified_time('j F Y'); ?>

    Here’s where it got weird. Every post that was modified before 6 februari 2021 shows the date 6 februari 2021. Every post that got updated after 6 februari 2021 shows the correct date.

    I double checked this. There are posts that haven’t been updated since 2014 or 2011, yet they show 6 februari 2021. I even went into phpMyAdmin and the post_modified field shows the correct date (not 6 februari 2021).

    Does anyone have an idea what it causing this or how to fix this? I have some suspects:

    • I’m using older php version: 7.2.34
    • I’m using an old sql server (WP site diagnose says so)
    • I vagely remember doing a database update, Yoast SEO did that for indexing purposes. It may have been around 6 februari? Can’t remember.
    • This topic was modified 3 years, 5 months ago by Peter_L.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    Are you sure you’re using the function within the post loop? When outside the loop, in many circumstances it’ll pick up the time of the last queried object, which may not be the post we’re interested in.

    If you’re within the post loop, the function is filterable. Your theme or a plugin could alter what it outputs, inadvertently affecting your usage. Narrow down the cause by selectively deactivating plugins or switching themes until the behavior goes away.

    Thread Starter Peter_L

    (@peter_l)

    I’m definitely in the loop. I just made a local copy, turned off all plugins. Problem still there.

    Moderator bcworkz

    (@bcworkz)

    I cannot replicate such behavior, so it appears to be a quirk of your site. The site I tested on happens to also be on PHP 7.2. Older MySQL wouldn’t change the data queried for. You’ve already confirmed the DB records are correct anyway, so the issue lies in PHP code somewhere. If you’ve deactivated all plugins, your theme is apparently the cause. If you switched to the default twentytwentyone theme (temporarily placing your code in one of its templates, single.php for example), you should see the correct modified date.

    Thread Starter Peter_L

    (@peter_l)

    Thanks for putting effort into this. I did switch to 2021, turned off all plugins and altered the 2021 template to show last modified date instead of published date and the problem remains the same. I even temporarily altered the name of yoast folder in plugins folder, just in case.

    I looked more into the DB and found a table wp_yoast_indexable table There, the rows have the incorrect date (the 6 februari) in the post_modified field. But how WP is still pulling data from that after disabling the yoast seo plugin, I don’t understand.

    I tried updating a post and the date modified updated just fine.

    I placed a topic on this issue in the yoast seo support https://www.ads-software.com/support/topic/incorrect-the_modified_time-post_modified/ but haven’t gotten an answer yet.

    • This reply was modified 3 years, 5 months ago by Peter_L.
    Moderator bcworkz

    (@bcworkz)

    You may have been seeing cached content when Yoast was inactive. Are you saying new modifications have the correct dates, only modifications prior to 6 February are a problem? Then the issue is solely within the table data. Current Yoast code is apparently correct. A custom one-time script to get modified dates from the posts table and update all 6 February data in the Yoast table would resolve that.

    It seems odd that Yoast would maintain redundant data. Even more odd that modifications before 6 February became corrupted. Hopefully the Yoast folks can provide more insight.

    Thread Starter Peter_L

    (@peter_l)

    I made a mistake. I looked at the DB wp_post table but didn’t realize there’s also rows for auto updates and revisions. When I looked at the actual post rows the date was in fact 6 feb. Still not sure how they all got 6 feb but I’m in the process of updating and cleaning up all posts anyway.
    Thanks for the help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘the_modified_time not correct’ is closed to new replies.