我正在为wordpress使用重力表单,并且我有以下功能来自动填充表单字段:
add_filter('gform_field_value_vendor_category', 'populate_post_vendor_category');
function populate_post_vendor_category($value){
global $post;
$vendor_category = the_terms( $post->ID, 'listing_category');
return $vendor_category;
}
将参数名称vendor_category
添加到表单中似乎不起作用。
我在一个模板文件上尝试了以下代码,它显示了当前的列表类别。
<?php global $post;
$vendor_cat = the_terms( $post->ID, 'listing_category');
echo $vendor_cat; ?>
不确定字段为什么不自动填充?
the terms
用于回显。使用get_the_terms()
来返回值。
get_the_terms( $id, $taxonomy );
根据经验,当您在wordpress中看不到前缀get_
时,该函数将在屏幕上回响。如the_title()
(回显)和get_the_title
(返回)。。