WordPress check if post modified date was more than 1 week ago

Ok so I have this code and im not sure exactly how to go about checking if the post modified date was more than a week ago.

So if the post was modified more than a week ago it should echo modified.

The code:

$sticky = get_option( 'sticky_posts' );
            if (count($sticky) > 0) {
                $stringSticky = implode(",", $sticky);
                $postsModifiedCheck = $wpdb->get_results(
                    "SELECT ID, post_modified
                    FROM `{$wpdb->prefix}posts`
                    WHERE post_status = 'publish' AND post_type = 'post'
                    AND ID IN ($stringSticky)"
                );

                $now = new DateTime();
                $currentDateTime = $now->getTimestamp();

                foreach ($postsModifiedCheck as $post) {
                    if ($currentDateTime > $post->post_modified) {
                        echo "modified";
                    }
                }
            }

So at the moment it will echo “modified”, just not sure how to modify the dates to echo “modified” if $post->post_modified more than a week ago.

Cheers

Read more here: WordPress check if post modified date was more than 1 week ago

Leave a Reply

Your email address will not be published. Required fields are marked *