当用户更新他们的个人资料时,我试图更新后元“produktadresse”。我无法指定元键,不知道该怎么做。有人有想法吗?
function my_profile_update( $user_id, $old_user_data ) {
$args = array(
'post_type' => 'produkt',
'numberposts' => -1
);
$all_posts = get_posts($args);
foreach ($all_posts as $single_post){
$user_id = get_current_user_id();
$user = get_user_meta( $user_id, 'benutzeradresse', true );
$lat = $user[lat];
$lng = $user[lng];
$adress = [ 'lat' => $lat, 'lng' => $lng ];
$id = $single_post;
$meta = get_metadata( $id, 'produktadresse');
update_post_meta( $id, 'produktadresse', $adress, $meta );
}
}
add_action( 'profile_update', 'my_profile_update', 10, 2 );