I have no experience with the get_{$meta_type}_metadata
filter either, hence all I can offer is a further approach to a possible workaround:
Iff you don’t need to satisfy third parties using get_post_meta
, but only want to use the filter in your own code, you could write a custom wrapper for get_post_meta
, which in turn will accept a filter:
function wpse94639_get_post_meta( $post_id, $key = '', $single = false ) {
$metadata = get_post_meta( $post_id, $key, $single );
return apply_filters( 'wpse94639', $metadata );
}
Now you could use add_filter( 'wpse94639', 'my_add_a_class_function' );
.
This is only a viable solution, iff you don’t need to filter results when some other theme/plugin is using the original get_post_meta
, obviously.