Title: WP_Comment::__get
Published: December 9, 2015
Last modified: August 20, 2026

---

# WP_Comment::__get( string $name ): mixed

## In this article

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

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

Magic getter.

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

If `$name` matches a post field, the comment post will be loaded and the post’s 
value returned.

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

 `$name`stringrequired

Property name.

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

 mixed

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

    ```php
    public function __get( $name ) {
    	if ( in_array( $name, $this->post_fields, true ) && 0 !== (int) $this->comment_post_ID ) {
    		$post = get_post( (int) $this->comment_post_ID );
    		if ( ! $post ) {
    			return null;
    		}
    		return $post->$name;
    	}
    	return null;
    }
    ```

[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/7.1/src/wp-includes/class-wp-comment.php#L512)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-comment.php#L512-L521)

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

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

Retrieves post data given a post ID or post object.

  |

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

| Version | Description | 
| [7.1.0](https://developer.wordpress.org/reference/since/7.1.0/) | Returns null instead of the global post’s field when the comment is not attached to a post, and no longer raises a warning when the comment’s post cannot be found. | 
| [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%2F__get%2F)
before being able to contribute a note or feedback.