0

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(); 
1
  • 1
    Why do you want to do this? What problem does it solve? – Tom J Nowell Nov 17 '20 at 1:37
0

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.

1
  • bro please i am getting errors, running it with queries, and as while i tried running it on php same thing, please can you specify the code to run it on php. thanks alot for your contribution. – KingSolomon Nov 17 '20 at 2:27
0
<?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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.