Title: WP_Comment::get_instance
Published: December 9, 2015
Last modified: April 28, 2025

---

# WP_Comment::get_instance( int $id ): 󠀁[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)󠁿|false

## In this article

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

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

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

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

 `$id`intrequired

Comment ID.

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

 [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)|false
Comment object, otherwise false.

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

    ```php
    public static function get_instance( $id ) {
    	global $wpdb;

    	$comment_id = (int) $id;
    	if ( ! $comment_id ) {
    		return false;
    	}

    	$_comment = wp_cache_get( $comment_id, 'comment' );

    	if ( ! $_comment ) {
    		$_comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id ) );

    		if ( ! $_comment ) {
    			return false;
    		}

    		wp_cache_add( $_comment->comment_ID, $_comment, 'comment' );
    	}

    	return new WP_Comment( $_comment );
    }
    ```

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

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_comment/get_instance/?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_cache_add()](https://developer.wordpress.org/reference/functions/wp_cache_add/)`wp-includes/cache.php` |

Adds data to the cache, if the cache key doesn’t already exist.

  | 
| [wpdb::get_row()](https://developer.wordpress.org/reference/classes/wpdb/get_row/)`wp-includes/class-wpdb.php` |

Retrieves one row from the database.

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

Retrieves the cache contents from the cache by key and group.

  | 
| [wpdb::prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/)`wp-includes/class-wpdb.php` |

Prepares a SQL query for safe execution.

  |

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

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

Retrieves comment data given a comment ID or comment object.

  |

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

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

## User Contributed Notes

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