2014-09-23 84 views
0

我有这个自定义职位类型称为“列表”。人们可以使用前端表单来创建新的列表。这个前端表单有一个名为“app_city”的自定义字段。现在,当有人提交表单时,我希望将这个自定义字段值自动转换为自定义分类“城市”(在我的cystom post type“listing”下)的一个词语。WordPress的:自动将自定义字段转换为自定义分类?

这样的事情有可能完成吗? 谢谢。

回答

0

是的,它可以通过wp_insert_term()。但是您必须挖掘处理app_city自定义字段数据的前端表单。在从窗体验证完成之后,只需使用wp_insert_term()即可。

+0

谢谢你,看看我下面的评论。 – RobbertT 2014-09-23 13:05:14

+0

@RobbertT你应该更新/编辑你的答案,而不是每次都创建一个新答案。 – 2014-09-24 03:52:11

0

好吧,所以这为我工作。 谢谢!

$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); 
相关问题