dongza1708 2019-04-06 10:51
浏览 82

如何在WordPress中发布文章时使用自定义ID

WordPress' post_id is not continuous, so I want to use a custom post_id in wordpress when post an article.

For example, I want to post an article as |id=2in database wp_posts, I got the position ofid=1` , what do I need to do in my function? I add it to my theme's functions.php

function reuse_old_id(){
    global $wpdb;
    $lastID = $wpdb->get_var("SELECT ID FROM (SELECT ID FROM $wpdb->posts ORDER BY ID ASC) T WHERE NOT EXISTS (SELECT 1 FROM $wpdb->posts WHERE ID=T.ID-1) LIMIT 1");
    $lastID++;
    // I tried the following code but the it didn't work
    $wpdb->query("ALTER TABLE $wpdb->posts AUTO_INCREMENT = $lastID");
}

  • 写回答

0条回答 默认 最新

    报告相同问题?