Posted by pcaisc, 07-21-2008, 08:25 AM | Hi there,
I'm working with wordpress and mysql database and I try to change the post
date on table wp_posts and column "post_date". Currently all my date is on
"2008-07-14 09:46:42" .
I want to run the sql query so it may change the
date later one day than each other like record 1 = 2008-07-14 09:46:42 ,
record 2 = 2008-07-15 09:46:42 , record 3 = 2008-07-16 09:46:42 and so
on...I've over 2000 posts right now and is impossible to change it manually.
anyone can help me what query should i use to change all this? also, I want
to change column "post_status" from "publish" to "future" , how can I do this
in sql query? I'm using phpmyadmin in my cpanel, and it have the ability to
insert query and all that.
Extremely appreciate your help here, and thanks in advanced!
|
Posted by volmasoft, 07-21-2008, 09:20 AM | I'm doing this from my phone so I can't gurantee it's all correct.
I'm assuming the primary key in wp_posts is post_id if not just modify that.
$SQL = mysql_query("SELECT `post_id` FROM `wp_posts` ORDER BY `post_id`") or die(mysql_error());
while($rs = mysql_fetch_array($SQL))
{
$count = 0;
$dateTime = strtotime('+ '.$count.' days', $start_date);
mysql_query("UPDATE `wp_posts` SET `post_date` = '$dateTime' WHERE `post_id` = '$rs[post_id]' LIMIT 1") or die(mysql_error());
$count++;
}
Someone else might need to re-read that got to shoot.
|
Posted by pcaisc, 07-21-2008, 11:43 AM | Thanks Volmasoft for your help here. I got this error while trying to put this code on phpmyadmin sql area:
SELECT `post_date` FROM `wp_posts` ORDER BY `post_date`
while($rs = mysql_fetch_array($SQL))
{
$count = 0;
$dateTime = strtotime('+ '.$count.' days', $start_date);
mysql_query("UPDATE `wp_posts` SET `post_date` = '$dateTime' WHERE `post_id` = '$rs[post_id]' LIMIT 1") or die(mysql_error());
$count++;
}
error shown is:
SQL query: Documentation
SELECT `post_date`
FROM `wp_posts`
ORDER BY `post_date` while(
$rs = mysql_fetch_array(
$SQL
)
){$count =0;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'while($rs = mysql_fetch_array($SQL))
{
$count = 0' at line 2
Last edited by pcaisc; 07-21-2008 at 11:54 AM.
|
Posted by volmasoft, 07-21-2008, 06:16 PM | You need to run it in a PHP script, you can't use that code in phpmyadmin directly. This is because I use loops to open up a second query to run the updates.
If you run it in a PHP file it should run. Any errors just message me, please please please backup your database first before running the script.
|
Posted by pcaisc, 07-21-2008, 09:12 PM | hi volmasoft,
extremely appreciate your help here.
When I execute the code in php, I got this error:
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/verabrad/public_html/date.php on line 47
Line 47 is:
var $dateTime = strtotime('+ '.$count.' days', $start_date);
and line 46 is:
var $count = 0;
|
Posted by pcaisc, 07-21-2008, 09:42 PM | hi volmasoft,
I think i got it now, but do you know why it just update to current date? i mean, the post update from july 14th to july 15th... until july 21st and stop.
Alot of records still stay at July 14th. I want it to be "+1" until future date.
And how do I modify the "publish" from table column "post_status" to "future" for all the record which had its date change?
thanks a million for your help here!
|
Posted by volmasoft, 07-22-2008, 03:12 PM | Swap:
To:
Swap:
To:
Last edited by volmasoft; 07-22-2008 at 03:15 PM.
Reason: To add in code tags
|
Posted by pcaisc, 07-22-2008, 10:15 PM | volmasoft,
It did the same, it will not update the status to future posts, and the date stop after today's date, it will not have it execute to future date. Any idea why is this so?
Thanks a million!
|
Posted by volmasoft, 07-23-2008, 05:11 AM | That is very odd, it should at least be updating the status to future.
Are you getting any error messages?
|
|
Add to Favourites
Print this Article |