_wp_preview_meta_filter

The timeline below displays how wordpress function _wp_preview_meta_filter has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Filters preview post meta retrieval to get values from the autosave.
 *
 * Filters revisioned meta keys only.
 *
 * @since 6.4.0
 *
 * @param mixed  $value     Meta value to filter.
 * @param int    $object_id Object ID.
 * @param string $meta_key  Meta key to filter a value for.
 * @param bool   $single    Whether to return a single value. Default false.
 * @return mixed Original meta value if the meta key isn't revisioned, the object doesn't exist,
 *               the post type is a revision or the post ID doesn't match the object ID.
 *               Otherwise, the revisioned meta value is returned for the preview.
 */
function _wp_preview_meta_filter($value, $object_id, $meta_key, $single)
{
    $post = get_post();
    if (empty($post) || $post->ID !== $object_id || !in_array($meta_key, wp_post_revision_meta_keys($post->post_type), true) || 'revision' === $post->post_type) {
        return $value;
    }
    $preview = wp_get_post_autosave($post->ID);
    if (false === $preview) {
        return $value;
    }
    return get_post_meta($preview->ID, $meta_key, $single);
}