After a lot of messing around with this, I think I found a fairly good solution here. I realize this is over a year after you asked but this was bothering me and I couldn’t find a good solution until now.
The problem is that the get_post_metadata function doesn’t allow you to access the current value. This means you aren’t able to transform the value, just replace it. I needed to append content to a meta field and where it was output did not allow filters of any kind.
Here’s my solution, altered to fit what this question asks:
function getqtlangcustomfieldvalue($metadata, $object_id, $meta_key, $single){
// Here is the catch, add additional controls if needed (post_type, etc)
$meta_needed = 'fields_titles';
if ( isset( $meta_key ) && $meta_needed == $meta_key ){
remove_filter( 'get_post_metadata', 'getqtlangcustomfieldvalue', 100 );
$current_meta = get_post_meta( $object_id, $meta_needed, TRUE );
add_filter('get_post_metadata', 'getqtlangcustomfieldvalue', 100, 4);
// Do what you need to with the meta value - translate, append, etc
// $current_meta = qtlangcustomfieldvalue_translate( $current_meta );
// $current_meta .= ' Appended text';
return $current_meta;
}
// Return original if the check does not pass
return $metadata;
}
add_filter( 'get_post_metadata', 'getqtlangcustomfieldvalue', 100, 4 );
This will keep any other get_post_metadata filters intact and allow modification of the original value.