WP_Comment::__get( string $name ): mixed

Magic getter.

Description

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

Parameters

$namestringrequired
Property name.

Return

mixed

Source

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;
}

Changelog

VersionDescription
7.1.0Returns 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.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.