Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author Khang Minh

    (@oddoneout)

    Can you post a link to your website and point out which items are having wrong date?

    Thanks.

    Thread Starter Astrogle

    (@astrogle)

    https://www.astrogle.com/post.xml
    see the top post was published(as scheduled) at 2nd april 2013, 00:45 hrs GMT
    but it was written(last modified) at 9:52 GMT on 1st april and xml sitemap doesnt show published/scheduled time

    Plugin Author Khang Minh

    (@oddoneout)

    Currently the plugin uses the post_modified field in the database. I believe this field doesn’t get updated when a post is published on a schedule, that’s why it’s showing “9:52 GMT on 1st april” (the last time at which you updated the post).

    Unless the time span between updating and publishing is long, I don’t see an issue. You can manually update the post to change the post_modified field, or add a filter to update post_modified field automatically when the post is published.

    Thread Starter Astrogle

    (@astrogle)

    i write once in a month and schedule posts to be published two or three per week.
    So, the time difference will be a lot if i schedule now and its published next month.
    Manually updating makes the idea of scheduling the posts go useless.
    Is there any way i can make this use ‘post_published’ field in database instead of post_modified field ?

    or how to add a filter to update post_modified field automatially

    Plugin Author Khang Minh

    (@oddoneout)

    This might help:

    https://codex.www.ads-software.com/Post_Status_Transitions

    Yours should be draft_to_publish. Your action could be something like (untested):

    function your_callback($post) {
    	if ('post' == $post['post_type']) {
    		wp_update_post($post);
    	}
    }
    add_action( 'draft_to_publish', 'your_callback' );
    Thread Starter Astrogle

    (@astrogle)

    i mean where to add the filter (which file?)

    Thread Starter Astrogle

    (@astrogle)

    i added it in theme’s functions.php but still sitemap shows modified time, not scheduled time

    Plugin Author Khang Minh

    (@oddoneout)

    The filter will only work on newly published posts, other posts that are already published need to be manually updated.

    Thread Starter Astrogle

    (@astrogle)

    okay it didn’t work for newly published post.
    if you look at the sitemap i linked above, out of the 2 posts published on 1st april, top one was actually scheduled to be published today (and it was published few hrs back).
    But it was written (last modified) on 1st april and now sitemap shows that date but not published date

    Plugin Author Khang Minh

    (@oddoneout)

    Perhaps we should use a different approach:

    https://betterwp.net/wordpress-plugins/google-xml-sitemaps/#module_api

    Just copy post.php in the default module folder to your module folder and edit that file as below:

    – Look for:

    $data['lastmod'] = $this->format_lastmod(strtotime($post->post_modified));

    – Change it to:

    $data['lastmod'] = $this->format_lastmod(strtotime($post->post_date));

    and it should be working (for all posts).

    Thread Starter Astrogle

    (@astrogle)

    Thanks.. this worked.
    May be if it takes whichever date is latest by comparing post_modified (VS) post_date , it would make better sitemap.xml
    (just a thought, may be useful for future updates of this plugin)

    Thread Starter Astrogle

    (@astrogle)

    well.. actually the approach you suggested is the best.
    if a post is modified, it just moves to the top of sitemap, may be requesting a revisit by bot, but its original published time is shows as modified time, which helps the link to given more priority (if similar content links or copied pages are elsewhere with later dates)

    Plugin Author Khang Minh

    (@oddoneout)

    I’m quite confused, so which approach do you prefer?

    Thread Starter Astrogle

    (@astrogle)

    actually the one you suggested is best.
    $data[‘lastmod’] = $this->format_lastmod(strtotime($post->post_date));
    that line does what is necessary.
    ignore my other post

    Thread Starter Astrogle

    (@astrogle)

    i’ve on more issue.
    https://www.astrogle.com/post.xml In this sitemap, 2nd link is latest published post on 8th april.
    But https://www.astrogle.com/sitemapindex.xml and its 4 sitemaps show last modified date as 6th april

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Post modified date,time doesn't match scheduled time’ is closed to new replies.