Override construct for secondary post type
This commit is contained in:
@@ -30,6 +30,22 @@ abstract class SP_Secondary_Post extends SP_Custom_Post {
|
|||||||
/** @var boolean Determines whether the date range is relative. */
|
/** @var boolean Determines whether the date range is relative. */
|
||||||
public $relative = false;
|
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' ) {
|
public function range( $where = '', $format = 'Y-m-d' ) {
|
||||||
$from = new DateTime( $this->from, new DateTimeZone( get_option( 'timezone_string' ) ) );
|
$from = new DateTime( $this->from, new DateTimeZone( get_option( 'timezone_string' ) ) );
|
||||||
$to = new DateTime( $this->to, new DateTimeZone( get_option( 'timezone_string' ) ) );
|
$to = new DateTime( $this->to, new DateTimeZone( get_option( 'timezone_string' ) ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user