Base::to_post( string $output = OBJECT, string $filter = 'raw' )
Returns the WP_Post version of this model.
Contents
Parameters
- $output
-
(string) (Optional) The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Post object,an associative array, or a numeric array, respectively.
Default value: OBJECT
- $filter
-
(string) (Optional) Type of filter to apply. Accepts 'raw', 'edit', 'db', or 'display' and other formats supported by the specific type implementation.
Default value: 'raw'
Return
(WP_Post|array|null) The post object version of this post type model or null if the post is not valid.
Source
File: src/Tribe/Models/Post_Types/Base.php
public function to_post( $output = OBJECT, $filter = 'raw' ) {
$properties = $this->get_properties( $filter );
// Clone the post to avoid side effects.
$post = clone $this->post;
// And decorate the clone with the properties.
foreach ( $properties as $key => $value ) {
$post->{$key} = $value;
}
switch ( $output ) {
case ARRAY_A:
return (array) $post;
case ARRAY_N:
return array_values( (array) $post );
case OBJECT:
default;
return $post;
}
}
Changelog
| Version | Description |
|---|---|
| 4.9.18 | Introduced. |