Are post ID’s reliable?

I understand that post ID’s are unique, but are they reliable as persistent data ID’s?

More specifically, is there a guarantee that, through a migration or another data exchange, post ID’s will not change?

I understand wordpress is primarily implemented using MySQL, so ID’s are governed by the AUTO_INCREMENT mechanism; however, is there any caveat on WordPress’ end that would change this behavior in the future, or potentially with another persistence implementation (such as MongoDB)?

5 s
5

The pedantic answer is NO.

While IDs are unique they can change without any change in UX as long as the change retains the consistency of the DB. And while creating a new post will generate a new unique ID, you can also create a post via code to reuse some “old” ID.

In practice they are reliable, but if reliability is very important to you then you need to attach some data to the post which will be used as the reliable identifier for your own needs.

Update: totally forgot about it because it is rarely used, and most of the time I seen it used it was used incorrectly, but wordpress has a reliable unique identifier by definition and it is the GUID

Leave a Comment