我试图更新一个图库字段,图像显示在前端,而不是后端。
// I have also tried to use the ACF field name like $field = \'field_xxxxxxxxxxxxx\';
$field = \'images\';
$post_id = 12345;
$attachments_ids = [
0 => 22222,
1 => 33333,
2 => 44444,
3 => 55555
];
update_field($field, $attachment_ids, $post_id);
SO网友:David Walz
我假设$attachments\\u id是您要保存的新值。
$field = get_field(\'images\');
$attachments_ids = [
0 => 22222,
1 => 33333,
2 => 44444,
3 => 55555
];
update_field($field, $attachment_ids, $post_id);
SO网友:Corgalore
我也遇到了这个问题。这对我很有用:
似乎只有在为选择器使用field\\u xxxx语法时才有效附件ID的数组应该是平坦的,没有indexkey
$field = \'field_xxxxxxxxxxxxx\';
$post_id = 12345;
$attachments_ids = [
22222,
33333,
44444,
55555
];
update_field($field, $attachment_ids, $post_id);