wp changing dates

Discussion in 'Blogging' started by blackhattrial, Mar 21, 2011.

  1. blackhattrial

    blackhattrial Regular Member

    Joined:
    Jul 22, 2008
    Messages:
    410
    Likes Received:
    131
    Location:
    black hat world -
    I have made some post on my word press blg and change dates to some past dates.


    Is it possible and if yes

    thx
     
  2. edgematch

    edgematch Elite Member

    Joined:
    May 24, 2010
    Messages:
    2,542
    Likes Received:
    1,954
    Occupation:
    You can never guess!
    Location:
    :noitacoL
    Yes of course. Attached is my gift to you. My opinion: One of the best scripts ever written.

    PHP:
    <?php
    // define mysql connect
    $dbname "dbname";
    $dbuser "dbuser";
    $dbpass "dbpass";
    $dbhost "localhost"// this can usually stay 'localhost'

    $wp_table "wp_posts"// define wordpress table name

    $gmt_offset '-8'// -8 for California, -5 New York, +8 Hong Kong, etc.

    $min_days_old 1// the minimum number of days old
    $max_days_old 20// the maximum number of days old

    // connect to db
    mysql_connect($dbhost,$dbuser,$dbpass);
    mysql_select_db($dbname);


    $result mysql_query("SELECT ID FROM $wp_table WHERE post_type = 'post'") or die(mysql_error());
    while (
    $l mysql_fetch_array($result)) {
        
    $post_id $l['ID'];
        echo 
    "Updating: $post_id <br>";

        
    $day rand($min_days_old$max_days_old);
        
    $hour rand(023);

        
    $new_date date'Y-m-d H:i:s'strtotime("-$day day -$hour hour") );
        
    $gmt_new_date date'Y-m-d H:i:s'strtotime("-$day day -$hour hour -$gmt_offset hour") );

        
    mysql_query("UPDATE $wp_table SET post_date='$new_date', post_date_gmt='$gmt_new_date',
        post_modified='
    $new_date', post_modified_gmt='$gmt_new_date' WHERE ID='$post_id'")
        or die(
    mysql_error());

    }

    echo 
    "<hr>DONE!";

    ?>
    1. save this as a php file (cpd.php) (you can tweak dates)
    2. put in the root folder of the domain
    3. run as http://www.mydomain.com/cpd.php
     
    • Thanks Thanks x 1
  3. blackhattrial

    blackhattrial Regular Member

    Joined:
    Jul 22, 2008
    Messages:
    410
    Likes Received:
    131
    Location:
    black hat world -
    WOW so does this mean we can change each date by hand and assign what ever date we want to assign

    too good. thanks
     
  4. edgematch

    edgematch Elite Member

    Joined:
    May 24, 2010
    Messages:
    2,542
    Likes Received:
    1,954
    Occupation:
    You can never guess!
    Location:
    :noitacoL
    It automatically changes the dates of all posts in your wp blog. But I think you can tweak it as you like.
     
  5. fantasy_andrei

    fantasy_andrei Newbie

    Joined:
    Apr 22, 2011
    Messages:
    18
    Likes Received:
    0
    how cand you tweak it ? :D