Support » Plugins » From draft to future posting into wordpress from my on script?

  • I’m having a similar issue as discussed in this in this post–>

    Basically, content articles are automatically posted to my blogs as “draft”. I wanted to automatically “future post” all these drafts by directly udating the wp_posts table. I wrote script was wrote to change post_status = “draft” to “future” and post_date post_date_gmt were incrementally future dated.
    Here is the basic outline of that script:

    $connect = mysql_connect("localhost", "user_name", "password");
    if (!$connect)
    {die('Could not connect: ' . mysql_error());}
    mysql_select_db("data_base_name", $connect) or die(mysql_error());
    echo "Connected to Database<br />";
    //time varibles
    $min = 60;//seconds
    $hour = 3600;//seconds
    $day = 86400;//seconds
    $week = 604800;//seconds
    $year = 31536000;//seconds
    $decade = 315360000;//seconds
    $date = date('Y-m-d H:i:s',time());//todays date
    $query = mysql_query('SELECT * FROM wp_posts WHERE post_status = "draft"  ORDER BY ID ASC');
    define("DATENOW",time(),true);//defines current timestamp as a constant
    $date_future = datenow;//defines initial value of future date
    //creates array for results
    $row = mysql_fetch_array($query);
    while($row = mysql_fetch_array($query))
    $rand_days = rand(1,7)*$day;//random number of 1-7 days
    $date_future = datenow + $rand_days + ($date_future - datenow);//add random 1-7 days to post time and increments post time
    $new_date = date('Y-m-d H:i:s',$date_future);//formats time for database entry
    $gmt_rand_days = date('Y-m-d H:i:s',$date_future + (10*$hour));//creates gmt date by adding five hours
    mysql_query('UPDATE wp_posts SET post_status = "future", post_date = "'.$new_date.'", post_date_gmt = "'.$gmt_rand_days.'"WHERE ID = "'.$row['ID'].'"');
    echo '<br />query was sucessfull';

    That script worked and updated the databases. The future posts would show up in the Manage post sections of the WP admin but would never “publish” after the future post date passed.

    After about two miserable weeks of trying to figure out why future posting was not working I discovered the WP cron system and how WP ads an array to the cron option name of the WordPress wp-options table.

    I have looked into the cron.php file but cannot make heads or tails of any of the functions. It seems I need wp_schedule_single_event( $timestamp, $hook, $args = array())

    With my current PHP/MySql skills I could easily write a script that would change posts marked as “draft” to “publish” at set predetermined time intervals. But that is not an options for me because there are several plugins that are triggered when a post is manually posted. The action of these plugins are bypassed if I directly make changes to the post_staus in the wp_post table.

    Is the a hack or plugin that does the following?:
    1. Search the WP wp_posts table for post_status = “draft” that meet specified criteria
    2. Change post_status form “draft” to “future”
    3. Add to cron in the the wp_options table so that as far as WP is concerned I posted these items were posted manually through the WP admin

  • The topic ‘From draft to future posting into wordpress from my on script?’ is closed to new replies.