Title: WP_REST_Comments_Controller::get_comment
Published: June 15, 2017
Last modified: August 20, 2026

---

# WP_REST_Comments_Controller::get_comment( int $id ): 󠀁[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)󠁿|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_comment/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_comment/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_comment/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_comment/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_comment/?output_format=md#changelog)

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

Get the comment, if the ID is valid.

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

 `$id`intrequired

Supplied ID.

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

 [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
Comment object if ID is valid, [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
otherwise.

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

    ```php
    protected function get_comment( $id ) {
    	$error = new WP_Error(
    		'rest_comment_invalid_id',
    		__( 'Invalid comment ID.' ),
    		array( 'status' => 404 )
    	);

    	if ( (int) $id <= 0 ) {
    		return $error;
    	}

    	$id      = (int) $id;
    	$comment = get_comment( $id );
    	if ( empty( $comment ) ) {
    		return $error;
    	}

    	if ( ! empty( $comment->comment_post_ID ) ) {
    		$post = get_post( (int) $comment->comment_post_ID );

    		if ( empty( $post ) ) {
    			return new WP_Error(
    				'rest_post_invalid_id',
    				__( 'Invalid post ID.' ),
    				array( 'status' => 404 )
    			);
    		}
    	}

    	return $comment;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php#L394)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php#L394-L424)

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

| Uses | Description | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

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

Retrieves post data given a post ID or post object.

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

Retrieves comment data given a comment ID or comment object.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

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

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

Checks if a given REST request has access to update a comment.

  | 
| [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_permissions_check()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/delete_item_permissions_check/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Checks if a given request has access to delete 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::get_item_permissions_check()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_permissions_check/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Checks if a given request has access to read the comment.

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

Retrieves a comment.

  |

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

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

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

## User Contributed Notes

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