Vehicle_URLs_By_VIN::find_vehicle_url( string $vin )

find_vehicle_url


Description Description

Takes a VIN and finds its permalink. If the vehicle is not in inventory, the vehicle archive URL is returned.


Top ↑

Parameters Parameters

$vin

(string) (Required) A vehicle identification number


Top ↑

Return Return

(string) A vehicle permalink or the link to the vehicle archive.


Top ↑

Source Source

File: includes/class-vehicle-urls-by-vin.php

		function find_vehicle_url( $vin ) {
			$posts = get_posts( array(
				'post_type'   => INVP::POST_TYPE,
				'post_status' => 'publish',
				'meta_key'    => apply_filters( 'invp_prefix_meta_key', 'vin' ),
				'meta_value'  => $vin,
			) );
			if( 1 === sizeof( $posts ) ) {
				return get_permalink( $posts[0] );
			}
			return get_post_type_archive_link( INVP::POST_TYPE );
		}