我有一个名为"Products"的定制post类型,还有一个名为"Price range"的分类法和一个名为"product-number"的自定义字段。
在价格范围内,我有一个术语叫"250 kr", "450kr", "580kr" and so on.
我需要的是有一种方法将数据添加到自定义字段中,根据它们所处的术语。
我想要的例子:
"250 kr"分类法术语中的所有产品都需要将200-"unique-number"添加到由高级自定义字段插件创建的"product-number"自定义字段中。
So 200-1, 200-2, 200-3 etc. and in the 450 I need 400-1, 400-2 and so on.我需要它来做所有以前创建的产品,也是当创建新的。因此,在创建新产品时,它需要查看它在哪些分类中,以及之前的“产品编号”是什么。
因此,如果最后一个产品是用"250 kr"术语创建的,并且产品编号为200-68,那么我创建的下一个产品需要在"product number"自定义字段中自动获得200-69。
我看过ACF的汽车侵权:
我试过添加一些条件,但不起作用。
add_option('ebo_dernier_num_club','3005','','no');
function ebo_renseigne_num_affiliation($value, $post_id, $field) {
if (! $value && get_post_type($post_id)=='club_type') {
$last_num = (int) get_option('ebo_dernier_num_club', '3000');
$last_num++;
update_option('ebo_dernier_num_club', $last_num);
$value = $last_num;
}
return $value;
}
add_filter('acf/update_value/name=numero_affiliation', 'ebo_renseigne_num_affiliation', 10, 3);我预计它将根据分类法术语和以前创建的产品自动递增。
发布于 2019-10-17 06:34:51
使用这个函数。update_field($selector,$value,$post_id);
您可以遵循以下链接:https://www.advancedcustomfields.com/resources/update_field/
https://stackoverflow.com/questions/58407227
复制相似问题