dozent_update_post_meta( int $post_id, string $meta_key, string|array|object $meta_value, string $prev_value = '' )

Updates a post meta field based on the given post ID. or delete existing meta if $meta_value is empty


Description

Use the $prev_value parameter to differentiate between meta fields with the same key and post ID.

If the meta field for the post does not exist, it will be added and its ID returned.

Example usage:

dozent_update_post_meta( $post_id, $meta_key, $meta_value );

Can be used in place of add_post_meta().

See also


Parameters

$post_id

(int) (Required) Post ID.

$meta_key

(string) (Required) Metadata key.

$meta_value

(string|array|object) (Required) Metadata value. Must be serializable if non-scalar.

$prev_value

(string) (Optional) Previous value to check before updating.

Default value: ''


Source

File: includes/core-functions.php

	function dozent_update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
		if ( ! empty( trim( $meta_value ) ) ) {
			update_post_meta( $post_id, $meta_key, $meta_value, $prev_value );
		} else {
			delete_post_meta( $post_id, $meta_key );
		}
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.