How does deleting a post work?

Continuing discussion from White screen of death when I'm trying to make a new post


By default, a deleted post remains in the database, with the Trash status, so it can be restored. After x days, the Trash is deleted from the database. The x days can be changed, and there is a filter on whether the Trash status is applied or the post is simply deleted. (it’s all variable) See https://developer.wordpress.org/reference/functions/wp_trash_post/

2 Likes

I know that it goes to the Trash. But what happens if you delete it from the Trash too. Does it go away completely or it leave an entry in the database?

Now that I’m looking at the post.php it says that each post takes a unique post ID. Where can I see the IDs of my posts?
Where do these post IDs get recorded? Is there a file or a list?

You can find the post id in the address bar when you are editing it.
Posts are in the _posts table of your database.
When you trash a post post_status column became “trash”. When you delete it’s row is deleted.

2 Likes

The Reveal IDs plugin shows you every post’s ID in the list of posts. I install this plugin on every site precisely for that reason.

3 Likes

A quick alternative to using a plugin is to add the following to your theme’s functions.php or, ideally, a MU plugin.

add_filter( 'manage_posts_columns', 'my_posts_columns_id', 5 );
add_action( 'manage_posts_custom_column', 'my_posts_custom_id_columns', 5, 2 );
add_filter( 'manage_pages_columns', 'my_posts_columns_id', 5);
add_action( 'manage_pages_custom_column', 'my_posts_custom_id_columns', 5, 2 );

function my_posts_columns_id( $defaults ) {
    $defaults['wps_post_id'] = __('Post ID');
    return $defaults;
}
function my_posts_custom_id_columns( $column_name, $id ){
    if( $column_name === 'wps_post_id' ) {
        echo $id;
    }
}

PS - I don’t claim credit for this code.

1 Like

This would be an excellent addition to the core, post ID column.

3 Likes

Yes!

At some point, WordPress removed it from the core (decision, not options), but IMHO it was a bad decision.

Created a petition for this, please, vote: Show Post/Page ID.

1 Like

Now I see why I received a notification for a new petition about this matter. ha ha ha
When I first saw the notification my first thought was… WTF do they read my mind?? HA HA HAAAAAAAAAAAAAAA

You can find the post id in the address bar when you are editing it.
Posts are in the _posts table of your database.
When you trash a post post_status column became “trash”. When you delete it’s row is deleted.

I have setup my website to use instead of the post ID the title of each post on the address bar. Does this affect or alter the post ID or this still exists either way as a number in the database?

4 posts were split to a new topic: Why close threads?

No, the post id is always a number. And you always see it when editing a post.

It is automatically closed when a post is marked as “solution”.

1 Like