您正在破坏$users
数组的每次迭代foreach
环要向数组中添加新项,应使用$users[] = {...}
, 不$users = {...}
.
function get_preselect_values()
{
$volunteers = get_post_meta($_POST[\'element_id\'], "volunteers", false);
$users = array();
foreach ($volunteers as $volunteer) {
foreach ($volunteer as $volun) {
$users[] = $volun[\'ID\'];
}
}
echo json_encode($users);
die;
}
add_action(\'wp_ajax_get_preselect_values\', \'get_preselect_values\');
add_action(\'wp_ajax_nopriv_get_preselect_values\', \'get_preselect_values\');