Setting datetime to be the post modified date instead of post created date?

Posted in: Newspaper
Post count: 230

I display the modified date on my site below the title, however the datetime still shows the posts original posting date. Is there anyway I can change this to show when it was updated? Want the latest date to show on search results. Code is:

    global $wp_version;
                    //old WP support
                    if (version_compare($wp_version, '5.3', '<')) {
                        $td_article_date = date(DATE_W3C, get_the_time('U', $this->post->ID));
                    } else {
                        // get_post_datetime() used from WP 5.3
                        $td_article_date = get_post_datetime($this->post->ID, 'date', 'gmt');
                        if ( $td_article_date !== false  ) {
                            $td_article_date = $td_article_date->format(DATE_W3C);
                        }
                    }
    
                    $buffy .= '<span class="td-post-date">';
                    $buffy .= '<time class="entry-date updated td-module-date' . $visibility_class . '" datetime="' . $td_article_date . '" >Last Updated: ' . get_the_modified_time(get_option('date_format'), $this->post->ID) . '</time>';
                    $buffy .= '</span>';

Have tried get_the_modified_date but it didn’t work. The instance in play is $td_article_date, and would really appreciate some help on this.

Thanks!

Edit: Got it working: $td_article_date = get_post_datetime($this->post->ID, ‘modified’, ‘gmt’);

Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.