From 4fc7184575c48ae03047f296aed7a21f6b01cc08 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 8 Nov 2017 19:06:49 +1100 Subject: [PATCH] Override construct for secondary post type --- .../abstracts/abstract-sp-secondary-post.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/abstracts/abstract-sp-secondary-post.php b/includes/abstracts/abstract-sp-secondary-post.php index 28d5a063..7737732c 100644 --- a/includes/abstracts/abstract-sp-secondary-post.php +++ b/includes/abstracts/abstract-sp-secondary-post.php @@ -30,6 +30,22 @@ abstract class SP_Secondary_Post extends SP_Custom_Post { /** @var boolean Determines whether the date range is relative. */ public $relative = false; + /** + * __construct function. + * + * @access public + * @param mixed $post + */ + public function __construct( $post ) { + if ( $post instanceof WP_Post || $post instanceof SP_Secondary_Post ): + $this->ID = absint( $post->ID ); + $this->post = $post; + else: + $this->ID = absint( $post ); + $this->post = get_post( $this->ID ); + endif; + } + public function range( $where = '', $format = 'Y-m-d' ) { $from = new DateTime( $this->from, new DateTimeZone( get_option( 'timezone_string' ) ) ); $to = new DateTime( $this->to, new DateTimeZone( get_option( 'timezone_string' ) ) );