Get only modified posts

You can use the posts_where filter:

// Add custom filter
add_filter( 'posts_where', 'wpse_modified' );

// Fetch posts
$query = new WP_Query( $lastupdated_args );

where you can define the filter callback as:

function wpse_modified( $where )
{
   global $wpdb;
   // Run only once:
   remove_filter( current_filter(), __FUNCTION__ );
   // Append custom SQL
   return $where . " AND {$wpdb->posts}.post_modified} != {$wpdb->posts}.post_modified} ';
}

Though it would be handy to be able to use this kind of date queries:

$args = [
    'date_query' => [
        [ 'before' => 'post_modified' ]
    ],
];

and

$args = [
    'date_query' => [
        [ 
            'column'    => 'post_modified_gmt', 
            'after'     => 'post_date_gmt', 
            'inclusive' => false 
        ]
    ],
];

That’s maybe an idea for a core ticket! 😉

Leave a Comment