invp_get_the_odometer( string $append = '', int $post_ID = null )

Template tag. Returns the odometer formatted as a number with comma separators if it is numeric. Returns any other non-zero value without any formatting. Adds the $append value to any return value but an empty string.

On This Page


Parameters Parameters

$append

(string) (Optional) A string to append after the odometer value. If the vehicle has no odometer value, then this parameter is ignored.

Default value: ''

$post_ID

(int) (Optional) The post ID of a vehicle. Must be passed when using this method outside the loop.

Default value: null


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/template-tags.php

function invp_get_the_odometer( $append = '', $post_ID = null ) {
	if ( empty( $post_ID ) ) {
		$post_ID = get_the_ID();
	}
	$raw = INVP::get_meta( 'odometer', $post_ID );

	if ( '0' === $raw ) {
		return apply_filters( 'invp_get_the_odometer', '', $post_ID );
	}

	$odometer = '';
	if ( is_numeric( $raw ) ) {
		$odometer .= number_format( $raw, 0, '.', ',' );
	} else {
		$odometer .= $raw;
	}

	if ( empty( $odometer ) ) {
		return apply_filters( 'invp_get_the_odometer', '', $post_ID );
	}

	// Did the user pass a string to append?
	if ( $append ) {
		$odometer .= $append;
	}
	return apply_filters( 'invp_get_the_odometer', $odometer, $post_ID );
}