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();
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();
Share
Improve this question
edited Nov 17, 2020 at 1:36
Tom J Nowell♦
61k7 gold badges79 silver badges148 bronze badges
asked Nov 17, 2020 at 1:02
KingSolomonKingSolomon
233 bronze badges
1
- 1 Why do you want to do this? What problem does it solve? – Tom J Nowell ♦ Commented Nov 17, 2020 at 1:37
2 Answers
Reset to default 1You 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.
<?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