WordPress的:自动将自定义字段转换为自定义分类?
问题描述:
我有这个自定义职位类型称为“列表”。人们可以使用前端表单来创建新的列表。这个前端表单有一个名为“app_city”的自定义字段。现在,当有人提交表单时,我希望将这个自定义字段值自动转换为自定义分类“城市”(在我的cystom post type“listing”下)的一个词语。WordPress的:自动将自定义字段转换为自定义分类?
这样的事情有可能完成吗? 谢谢。
答
好吧,所以这为我工作。 谢谢!
$parent_term = term_exists('Cities'); // array is returned if taxonomy is given
$parent_term_id = $parent_term['term_id']; // get numeric term id
$city = $_POST['app_plaatsnaam'];
wp_insert_term(
$_POST['app_city'], // the term
'Cities', // the taxonomy
array(
'parent'=> $parent_term_id
)
);
wp_set_object_terms($listing_id, $city, 'Cities', false);
谢谢你,看看我下面的评论。 – RobbertT 2014-09-23 13:05:14
@RobbertT你应该更新/编辑你的答案,而不是每次都创建一个新答案。 – 2014-09-24 03:52:11