我有树枝/木材功能,代码没有显示任何错误,但是当我在我的树枝模板中使用功能时出现错误,说'不是函数。无法识别自定义树枝功能
这是我在树枝模板我fucntions.php文件:
add_filter('timber/twig', function(\Twig_Environment $twig) {
$twig->addFunction(new Twig_Function('get_custom_meta', 'get_custom_meta'));
});
function get_custom_meta($key,$id){
if(empty($id)){
return types_render_field($key,array("raw"=>"true","separator"=>";"));
}else{
return get_post_meta($id, 'wpcf-'.$key, true);
}
}
这就是我如何调用模板中的函数。
{{ function(get_custom_meta('facebook', event.post_id)) }}
This in in wordpress。由于
get_custom_meta返回什么?我相信回报是空的。 –