INVP::get_meta( string $unprefixed_meta_key, int $post_id = null )

Retrieves post meta values.


Parameters Parameters

$unprefixed_meta_key

(string) (Required) A meta key suffix like ‘vin’ or ‘date_entered’.

$post_id

(int) (Optional) A vehicle post ID.

Default value: null


Top ↑

Return Return

(string|int|double|array)


Top ↑

Source Source

File: includes/class-invp.php

	public static function get_meta( $unprefixed_meta_key, $post_id = null ) {
		if ( empty( $post_id ) ) {
			$post_id = get_the_ID();
		}

		$meta_key = apply_filters( 'invp_prefix_meta_key', $unprefixed_meta_key );

		// Options are stored as a multi-valued meta field.
		$single = 'options_array' !== $unprefixed_meta_key;

		$meta_value = get_post_meta( $post_id, $meta_key, $single );
		// Kill dupes for singles. Added after finding duplicate date_entered and last_modified dates.
		if ( $single ) {
			$array_value = get_post_meta( $post_id, $meta_key );
			if ( $array_value && 1 < count( $array_value ) ) {
				delete_post_meta( $post_id, $meta_key );
				update_post_meta( $post_id, $meta_key, $meta_value );
			}
		}

		// If key is a number, return a number/zero instead of empty string.
		if ( self::meta_value_is_number( $meta_key ) ) {
			if ( empty( $meta_value ) ) {
				return 0;
			}
			if ( false === strpos( $meta_value ?? '', '.' ) ) {
				return (int) $meta_value;
			}
			return (float) $meta_value;
		}
		return $meta_value;
	}