I need to change the last modified date and time of all of my blog’s posts in WordPress. So far i have….
add_action( 'wp', 'asd' );
function asd()
{
$post_list = get_posts( array(
'post_per_page' => '-1'
) );
foreach ( $post_list as $post ) {
// $posts[] += $post->ID;
$postID = $post->ID;
$datetime = date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) );
echo $postID . ' ||| ' . $datetime . '<br>';
global $wpdb;
$wpdb->query( "UPDATE `$wpdb->posts` SET `post_modified` = '" . $datetime . "' WHERE ID = " . $postID);
}
}
I get no errors or whatsoever. I am using “echo” for debugging purposes. I have two problems.
- I have 6 posts and i get only 5
- It seems that no update is happening in the database, for the last modified field
Any help would be appreciated.
Read more here: Change WordPress Posts’ last_modified date and time with WP Query