WP_Post::__construct() WordPress Method

The WP_Post::__construct() method initializes a new post object. It accepts an post ID or a post object as its first parameter. If you pass an post ID, the method will retrieve the post data from the database and populate the object properties. If you pass an post object, the method will simply set the object properties.

WP_Post::__construct( WP_Post|object $post ) #

Constructor.


Parameters

$post

(WP_Post|object)(Required)Post object.


Top ↑

Source

File: wp-includes/class-wp-post.php

	public function __construct( $post ) {
		foreach ( get_object_vars( $post ) as $key => $value ) {
			$this->$key = $value;
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
3.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.