ไปเจอมา script random post wordpress
<?php
// define mysql connect
//Modified:
//1. Read name, user, passwd of db automatically
//2. Add "Get" Method: ?min=-1&max=-40 (be careful the minus)
//3. Add Minute Randomiztion
// Usage Example : 1. upload itself (domain root dir by the default)
// 2. http://www.domain.tld/RandomizePostTime?min=-1&max=-40
include "wp-config.php"; //change it when in subdir such as ../wp-config.php
$dbname = $DB_NAME; //database name
$dbuser = $DB_USER; //database username
$dbpass = $DB_PASSWORD; //your database password
$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 = $_GET["min"]; ; // the minimum number of days old
$max_days_old = $_GET["max"]; ; // 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_status = 'future'") 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(0, 23);
$minute = rand(0,60);
$new_date = date( 'Y-m-d H:i:s', strtotime("-$day day -$hour hour -$minute minute") );
$gmt_new_date = date( 'Y-m-d H:i:s', strtotime("-$day day -$hour hour -$gmt_offset hour -$minute minute") );
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!";
?>
เขียนบ่อยๆ นะ ชอบ
ตอบลบ