我试图在我的子主题的Functions.php中提取一个高级自定义字段,但它不起作用。有什么想法吗?
add_action('init', 'my_function_to_add_field_groups');
function my_function_to_add_field_groups() {
$section_name = get_field('section_name');
print "the $section_name";
}
答案 0 :(得分:0)
我所看到的几件事没有给出的更多上下文了:
您要访问的自定义字段不需要指定'post_id'吗?如果确实需要'post_id',则至少要进行调试,我会添加'post_id'作为参数:get_field('field_name', {Your Post ID});
当您定义print "the $section_name";
时,PHP假定您的变量是字符串的一部分,并且不希望被串联。您可以尝试快速组合字符串+变量,例如:print "the ".$section_name;
吗?