Inventory_Presser_Vehicle::__construct( int|null $post_id = null )

__construct


Description Description

Populates the object with vehicle data


Top ↑

Parameters Parameters

$post_id

(int|null) (Optional) The post ID of a vehicle

Default value: null


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-vehicle.php

		function __construct( $post_id = null )
		{
			_doing_it_wrong(
				__FUNCTION__,
				__( 'The vehicle class Inventory_Presser_Vehicle was deprecated as a method to access vehicle attributes in version 12.0.0. Use template tags instead. See https://inventorypresser.com/docs/template-tags/', 'inventory-presser' ),
				'12.0.0'
			);

			//Help the order by logic determine which post meta keys are numbers
			if( ! has_filter( 'invp_meta_value_or_meta_value_num', array( $this, 'indicate_post_meta_values_are_numbers' ) ) )
			{
				add_filter( 'invp_meta_value_or_meta_value_num', array( $this, 'indicate_post_meta_values_are_numbers' ), 10, 2 );
			}

			if( is_null( $post_id ) ) { return; }

			$this->post_ID = $post_id;
			$this->image_url = invp_get_the_photo_url( 'medium', $post_id );

			//get all data using the post ID
			$meta = get_post_meta( $post_id );

			//get these post meta values
			foreach( INVP::keys() as $key )
			{
				$filtered_key = apply_filters( 'invp_prefix_meta_key', $key );
				if( isset( $meta[$filtered_key] ) && isset( $meta[$filtered_key][0]))
				{
					if( is_array( $this->$key ) )
					{
						$this->$key = unserialize($meta[$filtered_key][0]);
					}
					else
					{
						$this->$key = trim($meta[$filtered_key][0]);
					}
				}
			}

			$this->transmission = invp_get_the_transmission( $post_id );
			$this->is_sold = invp_is_sold( $post_id );
			$this->is_wholesale = invp_is_wholesale( $post_id );
			$this->is_used = invp_is_used( $post_id );
			$this->location = invp_get_the_location( $post_id );
			$this->options_array = invp_get_the_options( $post_id );
		}