Query to find recently modified posts in WordPress

It can be sometime handy to query recently modified (last month or last few days) posts in wordpress mysql tables. Here are some handy queries:

Posts modified in last month

Approach 1 using MINUS

SELECT * from wp_posts where post_modified > NOW() - INTERVAL 1 MONTH
ORDER BY post_modified DESC;

Approach 2 using DATE_ADD

SELECT * from wp_posts where post_modified > DATE_ADD(NOW(), INTERVAL - 1 MONTH)
ORDER BY post_modified DESC;

Approach 3 using DATE_SUB

SELECT * from wp_posts where post_modified > DATE_SUB(NOW(), INTERVAL 1 MONTH)
ORDER BY post_modified DESC;

Posts modified in last week

SELECT * from wp_posts where post_modified > NOW() - INTERVAL 1 WEEK
ORDER BY post_modified DESC;

Posts modified in last 1 day

SELECT * from wp_posts where post_modified > NOW() - INTERVAL 1 DAY
ORDER BY post_modified DESC;

Posts modified in last 1 hour

SELECT * from wp_posts where post_modified > NOW() - INTERVAL 1 HOUR
ORDER BY post_modified DESC;
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments