danial dezfooli
danial dezfooli

Reputation: 818

Wordpress - Check if post has update

How can I check whether a post has been updated or not in Wordpress?

if (post_has_edit())
    the_modified_time();
else
    the_time();

Is there a function like post_has_edit()?

Upvotes: 3

Views: 3907

Answers (2)

Carlos Roman
Carlos Roman

Reputation: 88

If you need check date for multiple post on same page (for example: archive page, search page or any WP_Query), you can use

if(get_the_modified_date == get_the_date) :

    // Do stuff here

endif;

And remember use != for is not equal :)

Upvotes: 0

Maximillian Laumeister
Maximillian Laumeister

Reputation: 20359

From the Wordpress docs:

If the post or page is not yet modified, the modified time is the same as the creation time.

So you can just use the_modified_time(), and if the post hasn't been modified, it will return the creation time instead.

To check whether the post has been modified, check whether the_modified_time() == the_time().

Upvotes: 8

Related Questions