Meta data keys do not have to be unique, you can have multiple rows of the same key, each containing singular values. If you use get_post_meta
to fetch a key and don’t set the 3rd argument to true
, the function gets all the individual values and returns them as an array, which is not the same as getting a single value that is an array saved as a serialized string.
If you want to iterate over the returned array and save new values, you have to call update_post_meta
for each item in the array, and set the 4th argument of the function, which is the old value of the particular row you’d like to update.
$item_array = get_post_meta( $post->id, '_custom_post_type_onomies_relationship' );
foreach ( $item_array as $item_id ) {
$title = get_the_title( $item_id );
update_post_meta( $post->id, '_custom_post_type_onomies_relationship', $title, $item_id );
}