How to Update post_modified of all wordpress post

i want to update all my wordpress post modified date and time to a specific date and time,
i have a code to update it base on the id, but i want one to update all the row at once without putting the id of the posts .

$sql = "UPDATE Zulu_posts SET post_modified='2020-11-17 16:06:00' WHERE id=2";

if ($conn->query($sql) === TRUE) {
  echo "Record updated successfully";
} else {
  echo "Error updating record: " . $conn->error;
}

$conn->close(); 

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can use a generalized update query. As always, when dealing with databases take a backup first.

With that out of the way, your query should look something like:

BEGIN; -- Start a transaction
UPDATE
  wp_posts
SET
  post_modified = <Your new date>
  AND post_modified_gmt = <Your new date in GMT>;

SELECT * FROM wp_posts LIMIT 10 ORDER BY post_date DESC; -- See the 10 most recently authored posts, make sure their post_modified and post_modified_gmt looks good

COMMIT; -- Commit the changes to the database or
ROLLBACK; -- If things don't look right.

Edit: in your case, if you do this in PHP, definitely take a backup, and then make $sql everything above except for the lines with BEGIN, COMMIT, and ROLLBACK, though I’d recommend doing this in the command line or a GUI/web interface.

Method 2

<?php


$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "UPDATE zulu_posts SET post_modified_gmt = '2020-11-17-04:00:00'";
$sql = "UPDATE zulu_posts SET post_modified = '2020-11-17-04:00:00'";

if ($conn->query($sql) === TRUE) {
  echo "Record updated successfully";
} else {
  echo "Error updating record: " . $conn->error;
}

$conn->close();
?>

Ok bro this one worked, but i could like to add a form where by i can input the date and time i want and submit.
Please any idea on how i can do it


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x