WordPress-实现连续ID发布文章文章(亲测有效)

WordPress发布文章的时候,ID是随机的,全靠缘分分配文章ID,很多小伙伴用的ID当伪静态,都不知道发布多少文章了
下面就给出一个解决办法,免费分享给大家!!

function.php文件最后添加如下代码即可

//连续ID发布文章
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");
}

相关文章