Retrieves the Post Global Unique Identifier (guid).
Description
The guid will appear to be a link, but should not be used as an link to the post. The reason you should not use it as a link, is because of moving the blog across domains.
Parameters
$postint|WP_Postoptional- Post ID or post object. Default is global $post.
Source
function get_the_guid( $post = 0 ) {
$post = get_post( $post );
$post_guid = $post->guid ?? '';
$post_id = $post->ID ?? 0;
/**
* Filters the Global Unique Identifier (guid) of the post.
*
* @since 1.5.0
*
* @param string $post_guid Global Unique Identifier (guid) of the post.
* @param int $post_id The post ID.
*/
return apply_filters( 'get_the_guid', $post_guid, $post_id );
}
Hooks
- apply_filters( ‘get_the_guid’,
string $post_guid ,int $post_id ) Filters the Global Unique Identifier (guid) of the post.
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
Although “GUID” stands for Globally Unique Identifier, WordPress does not enforce a uniqueness constraint on the database level. In some cases—particularly when using plugins that publish posts without going through a draft state—multiple posts may share the same GUID value.
You should not use the GUID as a unique key for querying posts. Instead, use the post ID to guarantee uniqueness.