Using WordPress ‘get_comment_guid()’ PHP function

The get_comment_guid() WordPress PHP function retrieves the feed GUID for the current comment.

Usage

get_comment_guid($comment_id);

Input:

  • $comment_id (int|WP_Comment) – Optional comment object or ID. Defaults to global comment object.

Output:

  • A string containing the feed GUID for the specified comment.

Parameters

  • $comment_id (int|WP_Comment) – Optional comment object or ID. Defaults to global comment object.

More information

See WordPress Developer Resources: get_comment_guid()

Examples

Retrieve the feed GUID for a specific comment

This example retrieves the feed GUID for a comment with the ID of 25.

$comment_id = 25;
$comment_guid = get_comment_guid($comment_id);
echo $comment_guid;

Display the feed GUID for all comments on a post

This example displays the feed GUID for each comment on a post with the ID of 42.

$post_id = 42;
$comments = get_comments(array('post_id' => $post_id));

foreach ($comments as $comment) {
    $comment_guid = get_comment_guid($comment);
    echo "Comment GUID: " . $comment_guid . "<br>";
}

Retrieve the feed GUID for the current comment in a loop

This example retrieves the feed GUID for the current comment inside the comment loop.

while (have_comments()) {
    the_comment();
    $comment_guid = get_comment_guid();
    echo "Comment GUID: " . $comment_guid . "<br>";
}

Display the feed GUID for a list of comment IDs

This example displays the feed GUID for a list of specific comment IDs.

$comment_ids = array(12, 34, 56);

foreach ($comment_ids as $comment_id) {
    $comment_guid = get_comment_guid($comment_id);
    echo "Comment GUID: " . $comment_guid . "<br>";
}

Retrieve the feed GUID using a WP_Comment object

This example retrieves the feed GUID using a WP_Comment object for a comment with the ID of 45.

$comment_id = 45;
$comment = get_comment($comment_id);
$comment_guid = get_comment_guid($comment);
echo $comment_guid;