If you just need get_post_meta( $post_id, 'ywbc_barcode_display_value_custom_field', $single );
to return the value that’s stored in ean
, you can filter the get_post_meta()
call to return that value:
add_filter( 'get_post_metadata', 'wpse424858_filter_meta_value', 10, 4 );
/**
* Filters the barcode display meta value.
*
* @param mixed $value The existing meta value.
* @param int $id The post ID.
* @param string $key The meta key. We're looking for 'ywbc_barcode_display_value_custom_field'.
* @param bool $single Return a single value or an array?
*/
function wpse424858_filter_meta_value( $value, $id, $key, $single ) {
if ( 'ywbc_barcode_display_value_custom_field' === $key ) {
// Gets the value stored in the 'ean' meta.
return get_post_meta( $id, 'ean', $single );
}
// Otherwise, returns what we were provided.
return $value;
}
Note: This code is untested and is meant as a starting point rather than a finished product. Try it out on a test site before putting it into production.
Doing it this way means that there’s not a duplication of data in your DB.
References
get_{$meta_type}_metadata
filter (the{$meta_type}
in this case ispost
)