admin管理员组文章数量:1315786
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
本文标签: phpHow to Update postmodified of all wordpress post
版权声明:本文标题:php - How to Update post_modified of all wordpress post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741989291a2408874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论