The posts table, wp_posts
is probably the most important table in the WordPress database but it does not contain only blog posts as its name implies. It stores various types of content including posts, pages, menu items, media attachments and any custom post types (CPT) that a site uses.
The ID
column of this table is the unique number assigned to each content entry.
The table’s content nature is provided by the post_type
column which denotes if the row is a post, page, attachment, nav_menu_item or another type, so none of above can be assigned the same ID
by WordPress.
So unless you manually modify the database (which would be a bad move), ID
‘s are unique within a blog/site.
Multisite
However, within a WordPress Multisite Network, ID
‘s are not unique. A post on one site can have the same ID
as a post on another site, since each sub-site has a separate database/tables.
In such case you can use $post->guid
instead of $post->ID
. guid
means Global Unique Identifier and this is WordPress’ tool for this exact purpose, to be unique in the entire network.
NB: The guid must be in lowercaps for it to work.