Using WordPress ‘get_comment_to_edit()’ PHP function

The get_comment_to_edit() WordPress PHP function returns a WP_Comment object based on the given comment ID.

Usage

get_comment_to_edit($id);

Input:

$id = 5;

Output:
WP_Comment object for the comment with ID 5.

Parameters

  • $id (int) – Required. The ID of the comment to retrieve.

More information

See WordPress Developer Resources: get_comment_to_edit()

Examples

Display comment content for editing

This example retrieves a comment with a specified ID and displays its content for editing.

$comment_id = 5;
$comment = get_comment_to_edit($comment_id);
echo 'Edit Comment: ' . $comment->comment_content;

Display comment author’s email

This example retrieves a comment by its ID and displays the author’s email.

$comment_id = 7;
$comment = get_comment_to_edit($comment_id);
echo 'Author Email: ' . $comment->comment_author_email;

Check if comment is approved

This example checks if a comment with a specified ID is approved or not.

$comment_id = 12;
$comment = get_comment_to_edit($comment_id);
$is_approved = $comment->comment_approved == 1 ? 'Approved' : 'Not Approved';
echo 'Comment Status: ' . $is_approved;

Display comment’s parent ID

This example retrieves a comment by its ID and displays its parent comment’s ID.

$comment_id = 18;
$comment = get_comment_to_edit($comment_id);
echo 'Parent Comment ID: ' . $comment->comment_parent;

Display comment date in a custom format

This example retrieves a comment by its ID and displays its date in a custom format.

$comment_id = 21;
$comment = get_comment_to_edit($comment_id);
$date_format = 'F j, Y';
echo 'Comment Date: ' . date($date_format, strtotime($comment->comment_date));