Title: get_comment
Published: April 25, 2014
Last modified: April 28, 2025

---

# get_comment( WP_Comment|string|int $comment = null, string $output = OBJECT ): 󠀁[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)󠁿|array|null

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#wp--skip-link--target)

Retrieves comment data given a comment ID or comment object.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#description)󠁿

If an object is passed then the comment data will be cached and then returned after
being passed through a filter. If the comment is empty, then the global comment 
variable will be used, if it is set.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#parameters)󠁿

 `$comment`[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
|string|intoptional

Comment to retrieve.

Default:`null`

`$output`stringoptional

The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
a [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/) object,
an associative array, or a numeric array, respectively.

Default:`OBJECT`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#return)󠁿

 [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)|array
|null Depends on $output value.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#source)󠁿

    ```php
    function get_comment( $comment = null, $output = OBJECT ) {
    	if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) {
    		$comment = $GLOBALS['comment'];
    	}

    	if ( $comment instanceof WP_Comment ) {
    		$_comment = $comment;
    	} elseif ( is_object( $comment ) ) {
    		$_comment = new WP_Comment( $comment );
    	} else {
    		$_comment = WP_Comment::get_instance( $comment );
    	}

    	if ( ! $_comment ) {
    		return null;
    	}

    	/**
    	 * Fires after a comment is retrieved.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param WP_Comment $_comment Comment data.
    	 */
    	$_comment = apply_filters( 'get_comment', $_comment );

    	if ( OBJECT === $output ) {
    		return $_comment;
    	} elseif ( ARRAY_A === $output ) {
    		return $_comment->to_array();
    	} elseif ( ARRAY_N === $output ) {
    		return array_values( $_comment->to_array() );
    	}
    	return $_comment;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/comment.php#L221)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/comment.php#L221-L255)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#hooks)󠁿

 [apply_filters( ‘get_comment’, WP_Comment $_comment )](https://developer.wordpress.org/reference/hooks/get_comment/)

Fires after a comment is retrieved.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Comment::__construct()](https://developer.wordpress.org/reference/classes/wp_comment/__construct/)`wp-includes/class-wp-comment.php` |

Constructor.

  | 
| [WP_Comment::get_instance()](https://developer.wordpress.org/reference/classes/wp_comment/get_instance/)`wp-includes/class-wp-comment.php` |

Retrieves a [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/) instance.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#)

| Used by | Description | 
| [_get_comment_reply_id()](https://developer.wordpress.org/reference/functions/_get_comment_reply_id/)`wp-includes/comment-template.php` |

Gets the comment’s reply to ID from the $_GET[‘replytocom’].

  | 
| [wp_get_unapproved_comment_author_email()](https://developer.wordpress.org/reference/functions/wp_get_unapproved_comment_author_email/)`wp-includes/comment.php` |

Gets unapproved comment author’s email.

  | 
| [get_object_subtype()](https://developer.wordpress.org/reference/functions/get_object_subtype/)`wp-includes/meta.php` |

Returns the object subtype for a given object ID of a specific type.

  | 
| [WP_REST_Comments_Controller::get_comment()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_comment/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Get the comment, if the ID is valid.

  | 
| [WP_REST_Comments_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Updates a comment.

  | 
| [WP_REST_Comments_Controller::delete_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/delete_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Deletes a comment.

  | 
| [WP_REST_Comments_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Creates a comment.

  | 
| [WP_Comment_Query::fill_descendants()](https://developer.wordpress.org/reference/classes/wp_comment_query/fill_descendants/)`wp-includes/class-wp-comment-query.php` |

Fetch descendants for located comments.

  | 
| [wp_handle_comment_submission()](https://developer.wordpress.org/reference/functions/wp_handle_comment_submission/)`wp-includes/comment.php` |

Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form.

  | 
| [wp_new_comment_notify_moderator()](https://developer.wordpress.org/reference/functions/wp_new_comment_notify_moderator/)`wp-includes/comment.php` |

Sends a comment moderation notification to the comment moderator.

  | 
| [wp_new_comment_notify_postauthor()](https://developer.wordpress.org/reference/functions/wp_new_comment_notify_postauthor/)`wp-includes/comment.php` |

Sends a notification of a new comment to the post author.

  | 
| [WP_Comments_List_Table::floated_admin_avatar()](https://developer.wordpress.org/reference/classes/wp_comments_list_table/floated_admin_avatar/)`wp-admin/includes/class-wp-comments-list-table.php` |

Adds avatars to comment author names.

  | 
| [WP_Comment_Query::get_comments()](https://developer.wordpress.org/reference/classes/wp_comment_query/get_comments/)`wp-includes/class-wp-comment-query.php` |

Get a list of comments matching the query vars.

  | 
| [get_avatar_data()](https://developer.wordpress.org/reference/functions/get_avatar_data/)`wp-includes/link-template.php` |

Retrieves default data about the avatar.

  | 
| [touch_time()](https://developer.wordpress.org/reference/functions/touch_time/)`wp-admin/includes/template.php` |

Prints out HTML form date elements for editing post or comment publish date.

  | 
| [_wp_ajax_delete_comment_response()](https://developer.wordpress.org/reference/functions/_wp_ajax_delete_comment_response/)`wp-admin/includes/ajax-actions.php` |

Sends back current comment total and new page links if they need to be updated.

  | 
| [wp_ajax_delete_comment()](https://developer.wordpress.org/reference/functions/wp_ajax_delete_comment/)`wp-admin/includes/ajax-actions.php` |

Handles deleting a comment via AJAX.

  | 
| [wp_ajax_dim_comment()](https://developer.wordpress.org/reference/functions/wp_ajax_dim_comment/)`wp-admin/includes/ajax-actions.php` |

Handles dimming a comment via AJAX.

  | 
| [wp_ajax_get_comments()](https://developer.wordpress.org/reference/functions/wp_ajax_get_comments/)`wp-admin/includes/ajax-actions.php` |

Handles getting comments via AJAX.

  | 
| [wp_ajax_replyto_comment()](https://developer.wordpress.org/reference/functions/wp_ajax_replyto_comment/)`wp-admin/includes/ajax-actions.php` |

Handles replying to a comment via AJAX.

  | 
| [wp_ajax_edit_comment()](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/)`wp-admin/includes/ajax-actions.php` |

Handles editing a comment via AJAX.

  | 
| [WP_Comments_List_Table::column_comment()](https://developer.wordpress.org/reference/classes/wp_comments_list_table/column_comment/)`wp-admin/includes/class-wp-comments-list-table.php` |  | 
| [get_comment_to_edit()](https://developer.wordpress.org/reference/functions/get_comment_to_edit/)`wp-admin/includes/comment.php` |

Returns a [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/) object based on comment ID.

  | 
| [floated_admin_avatar()](https://developer.wordpress.org/reference/functions/floated_admin_avatar/)`wp-admin/includes/comment.php` |

Adds avatars to relevant places in admin.

  | 
| [map_meta_cap()](https://developer.wordpress.org/reference/functions/map_meta_cap/)`wp-includes/capabilities.php` |

Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked.

  | 
| [get_avatar()](https://developer.wordpress.org/reference/functions/get_avatar/)`wp-includes/pluggable.php` |

Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post.

  | 
| [wp_notify_postauthor()](https://developer.wordpress.org/reference/functions/wp_notify_postauthor/)`wp-includes/pluggable.php` |

Notifies an author (and/or others) of a comment/trackback/pingback on a post.

  | 
| [wp_notify_moderator()](https://developer.wordpress.org/reference/functions/wp_notify_moderator/)`wp-includes/pluggable.php` |

Notifies the moderator of the site about a new comment that is awaiting approval.

  | 
| [get_commentdata()](https://developer.wordpress.org/reference/functions/get_commentdata/)`wp-includes/deprecated.php` |

Retrieve an array of comment data about comment $comment_id.

  | 
| [wp_scheduled_delete()](https://developer.wordpress.org/reference/functions/wp_scheduled_delete/)`wp-includes/functions.php` |

Permanently deletes comments or posts of any type that have held a status of ‘trash’ for the number of days defined in EMPTY_TRASH_DAYS.

  | 
| [get_edit_comment_link()](https://developer.wordpress.org/reference/functions/get_edit_comment_link/)`wp-includes/link-template.php` |

Retrieves the edit comment link.

  | 
| [edit_comment_link()](https://developer.wordpress.org/reference/functions/edit_comment_link/)`wp-includes/link-template.php` |

Displays the edit comment link with formatting.

  | 
| [get_comment_guid()](https://developer.wordpress.org/reference/functions/get_comment_guid/)`wp-includes/feed.php` |

Retrieves the feed GUID for the current comment.

  | 
| [wp_xmlrpc_server::wp_deleteComment()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/wp_deletecomment/)`wp-includes/class-wp-xmlrpc-server.php` |

Deletes a comment.

  | 
| [wp_xmlrpc_server::wp_editComment()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/wp_editcomment/)`wp-includes/class-wp-xmlrpc-server.php` |

Edits a comment.

  | 
| [wp_xmlrpc_server::wp_getComment()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/wp_getcomment/)`wp-includes/class-wp-xmlrpc-server.php` |

Retrieves a comment.

  | 
| [comment_form_title()](https://developer.wordpress.org/reference/functions/comment_form_title/)`wp-includes/comment-template.php` |

Displays text based on comment reply status.

  | 
| [get_comment_reply_link()](https://developer.wordpress.org/reference/functions/get_comment_reply_link/)`wp-includes/comment-template.php` |

Retrieves HTML content for reply to comment link.

  | 
| [get_comment_link()](https://developer.wordpress.org/reference/functions/get_comment_link/)`wp-includes/comment-template.php` |

Retrieves the link to a given comment.

  | 
| [get_comment_text()](https://developer.wordpress.org/reference/functions/get_comment_text/)`wp-includes/comment-template.php` |

Retrieves the text of the current comment.

  | 
| [comment_text()](https://developer.wordpress.org/reference/functions/comment_text/)`wp-includes/comment-template.php` |

Displays the text of the current comment.

  | 
| [get_comment_time()](https://developer.wordpress.org/reference/functions/get_comment_time/)`wp-includes/comment-template.php` |

Retrieves the comment time of the current comment.

  | 
| [get_comment_type()](https://developer.wordpress.org/reference/functions/get_comment_type/)`wp-includes/comment-template.php` |

Retrieves the comment type of the current comment.

  | 
| [comment_author_url()](https://developer.wordpress.org/reference/functions/comment_author_url/)`wp-includes/comment-template.php` |

Displays the URL of the author of the current comment, not linked.

  | 
| [get_comment_class()](https://developer.wordpress.org/reference/functions/get_comment_class/)`wp-includes/comment-template.php` |

Returns the classes for the comment div as an array.

  | 
| [get_comment_date()](https://developer.wordpress.org/reference/functions/get_comment_date/)`wp-includes/comment-template.php` |

Retrieves the comment date of the current comment.

  | 
| [get_comment_excerpt()](https://developer.wordpress.org/reference/functions/get_comment_excerpt/)`wp-includes/comment-template.php` |

Retrieves the excerpt of the given comment.

  | 
| [comment_excerpt()](https://developer.wordpress.org/reference/functions/comment_excerpt/)`wp-includes/comment-template.php` |

Displays the excerpt of the current comment.

  | 
| [get_comment_ID()](https://developer.wordpress.org/reference/functions/get_comment_id/)`wp-includes/comment-template.php` |

Retrieves the comment ID of the current comment.

  | 
| [get_comment_author()](https://developer.wordpress.org/reference/functions/get_comment_author/)`wp-includes/comment-template.php` |

Retrieves the author of the current comment.

  | 
| [comment_author()](https://developer.wordpress.org/reference/functions/comment_author/)`wp-includes/comment-template.php` |

Displays the author of the current comment.

  | 
| [get_comment_author_email()](https://developer.wordpress.org/reference/functions/get_comment_author_email/)`wp-includes/comment-template.php` |

Retrieves the email of the author of the current comment.

  | 
| [comment_author_email()](https://developer.wordpress.org/reference/functions/comment_author_email/)`wp-includes/comment-template.php` |

Displays the email of the author of the current global $comment.

  | 
| [get_comment_author_email_link()](https://developer.wordpress.org/reference/functions/get_comment_author_email_link/)`wp-includes/comment-template.php` |

Returns the HTML email link to the author of the current comment.

  | 
| [get_comment_author_link()](https://developer.wordpress.org/reference/functions/get_comment_author_link/)`wp-includes/comment-template.php` |

Retrieves the HTML link to the URL of the author of the current comment.

  | 
| [get_comment_author_IP()](https://developer.wordpress.org/reference/functions/get_comment_author_ip/)`wp-includes/comment-template.php` |

Retrieves the IP address of the author of the current comment.

  | 
| [get_comment_author_url()](https://developer.wordpress.org/reference/functions/get_comment_author_url/)`wp-includes/comment-template.php` |

Retrieves the URL of the author of the current comment, not linked.

  | 
| [wp_set_comment_status()](https://developer.wordpress.org/reference/functions/wp_set_comment_status/)`wp-includes/comment.php` |

Sets the status of a comment.

  | 
| [wp_update_comment()](https://developer.wordpress.org/reference/functions/wp_update_comment/)`wp-includes/comment.php` |

Updates an existing comment in the database.

  | 
| [wp_spam_comment()](https://developer.wordpress.org/reference/functions/wp_spam_comment/)`wp-includes/comment.php` |

Marks a comment as Spam.

  | 
| [wp_unspam_comment()](https://developer.wordpress.org/reference/functions/wp_unspam_comment/)`wp-includes/comment.php` |

Removes a comment from the Spam.

  | 
| [wp_get_comment_status()](https://developer.wordpress.org/reference/functions/wp_get_comment_status/)`wp-includes/comment.php` |

Retrieves the status of a comment by comment ID.

  | 
| [wp_insert_comment()](https://developer.wordpress.org/reference/functions/wp_insert_comment/)`wp-includes/comment.php` |

Inserts a comment into the database.

  | 
| [get_page_of_comment()](https://developer.wordpress.org/reference/functions/get_page_of_comment/)`wp-includes/comment.php` |

Calculates what page number a comment will appear on for comment paging.

  | 
| [wp_delete_comment()](https://developer.wordpress.org/reference/functions/wp_delete_comment/)`wp-includes/comment.php` |

Trashes or deletes a comment.

  | 
| [wp_trash_comment()](https://developer.wordpress.org/reference/functions/wp_trash_comment/)`wp-includes/comment.php` |

Moves a comment to the Trash

  | 
| [wp_untrash_comment()](https://developer.wordpress.org/reference/functions/wp_untrash_comment/)`wp-includes/comment.php` |

Removes a comment from the Trash

  |

[Show 62 more](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#comment-content-707)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_comment/#comment-707)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%23comment-707)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%23comment-707)
 4.  **Example**
      To get the author’s name of a comment with ID 7:
 5.      ```php
         <?php
         $my_id = 7;
         $comment_id_7 = get_comment( $my_id ); 
         $name = $comment_id_7->comment_author;
         ?>
         ```
     
 6.  Alternatively, specify the `$output` parameter:
 7.      ```php
         <?php
         $my_id = 7;
         $comment_id_7 = get_comment( $my_id, ARRAY_A );
         $name = $comment_id_7['comment_author'];
         ?>
         ```
     
 8.      ```php
         <?php
         //	Correct: pass a dummy variable as post_id
         $the_comment = & get_comment( $dummy_id = 7 );
     
         //	Incorrect: literal integer as post_id
         $the_comment = & get_comment( 7 );
         //	Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference'
         ?>
         ```
     
 9.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%3Freplytocom%3D707%23feedback-editor-707)
 10.  [Skip to note 5 content](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#comment-content-706)
 11.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_comment/#comment-706)
 12. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%23comment-706)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%23comment-706)
 13. **Example**
      To get the author’s name of a comment with ID 7:
 14.     ```php
         <?php
         $my_id = 7;
         $comment_id_7 = get_comment( $my_id, ARRAY_A );
         $name = $comment_id_7['comment_author'];
         ?>
         ```
     
 15.     ```php
         <?php
         //	Correct: pass a dummy variable as post_id
         $the_comment = & get_comment( $dummy_id = 7 );
     
         //	Incorrect: literal integer as post_id
         $the_comment = & get_comment( 7 );
         //	Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference'
         ?>
         ```
     
 16.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%3Freplytocom%3D706%23feedback-editor-706)
 17.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/get_comment/?output_format=md#comment-content-3917)
 18.   [edyd](https://profiles.wordpress.org/edyd/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_comment/#comment-3917)
 19. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%23comment-3917)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%23comment-3917)
 20. Grab the title and link of the post from the comment
 21.     ```php
         <?php
         $comentario = get_comment( $comment_ID, OBJECT );
         $title_post = get_the_title( $comentario->comment_post_ID );
         $link_post = get_permalink( $comentario->comment_post_ID );
         ?>
         ```
     
 22.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F%3Freplytocom%3D3917%23feedback-editor-3917)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment%2F)
before being able to contribute a note or feedback.