Does an article (post) id ever change?

No they don’t change, but you shouldn’t rely on them for external sites.

If we’re talking about purely in the database on an individual WordPress site, then:

  • If it’s a published/established post/page then yes, the ID will not change other than to delete it
  • If its a revision, a draft, etc the ID won’t change, but it won’t survive for very long either. It would be a poor piece of data to attach to

Once we move outside of that realm though, we enter the realm of data portability. If you export the data or rely on RSS, the post ID isn’t available, and doesn’t survive imports and exports.

So What Should I Do If I’m…

For Tables and storing references to posts in the database or Post Meta

Use Post IDs.

For detecting duplicates on other sites/programs outside your WordPress install

Use post GUIDs. These are passed around via RSS and others, and should remain the same so long as your posts URL doesn’t wildly change.

To put in my code

Never hardcode post IDs in a theme, they’re what we call ‘magic values’, and they’re horrificly bad practice in programming. Not just WordPress, but any code that has these is bad code by definition. AVoid like the plague.

Use a post ID stored in an option with a GUI to set it in the dashboard area, or pull post IDs from posts in a term with a known slug.

For a custom table or custom data storage

I would advise you rely instead on custom taxonomies and post meta. Your custom tables are very likely to be both unnecessary, and not as performant as they’ll not be picked up by a lot of the caching mechanisms.

If you’re doing this so you can list latest blogposts on site A in the sidebar of site B

Then you should either pull them in using RSS ( perhaps a custom widget so you can style them appropriately ), or use a multisite installation.

Internally though, always refer to a post by its ID

Want to know about Terms and Categories

Same applies, use term IDs internally, use Term slugs externally.

URLs

You mentioned URLs. The reason you have ?p=86 etc is because you don’t have permalinks enabled.

But if you did have permalinks enabled, the ?p=86 url would still work.

E.g. These URLs on my site both work:

Other peoples permalinks may not take the same format.