wordpress文章实现连续ID发布文章
WordPress发布文章的时候,ID是随机的,很是蛋疼!很多小伙伴用的ID当伪静态,都不知道发布多少文章了
下面就给出一个解决办法,免费分享给大家!!
重点来了
function.php文件最后添加如下代码即可
function keep_id_continuous()
{
global $wpdb;
$lastID = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' OR post_status = 'draft' OR post_status = 'private' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ORDER BY ID DESC LIMIT 1");
$wpdb->query("DELETE FROM $wpdb->posts WHERE ( post_status = 'auto-draft' OR ( post_status = 'inherit' AND post_type = 'revision' ) ) AND ID > $lastID");
$lastID++;
$wpdb->query("ALTER TABLE $wpdb->posts AUTO_INCREMENT = $lastID");
}
好了 ,添加上这个代码后,会按照最近发布的ID递增上去!!