我有一个带有 2 个元框的 CPT。1 = mv_facility_code
2 =mv_facility_email
所有用户都有 dB 列user_facility
和user_facility_email
当站点管理员进入 CPT 并更改时,mv_facility_email
我试图找到user_facility
值匹配的所有用户mv_facility_code
并将其元数据从值更改user_facility_email
为新的mv_facility_email
.
这是我正在尝试的,但它不起作用。
add_action( 'save_post_cpt', 'mv_update_user_facility_details' );
function mv_update_user_facility_details() {
$facility_code = get_post_meta($post->ID, 'mv_facility_code', true);
$facility_email = get_post_meta($post->ID, 'mv_facility_email', true);
$args = array(
'meta_key' => 'user_facility',
'meta_value' => $facility_code,
);
$user_query = new WP_User_Query();
$users = $user_query->get_results();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
update_user_meta( $user->user_id, 'user_facility_email', $facility_email );
}
};
};
一如既往,非常感谢任何帮助理解我的错误。