I am trying to pull an Advanced Custom Field in my Functions.php of my child theme and it's not working. Any ideas?
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";
}
A couple things i'm seeing without having any more context then what's given:
Is the custom field you're trying to access one that does not require specifying the 'post_id'? If it does require 'post_id', for debugging at least i would give adding the 'post_id' as a parameter: get_field('field_name', {Your Post ID});
When you define print "the $section_name";
PHP is assuming that your variable is part of the string and not meant to be concatenated. Can you try a quick concatenation of the string+variable like: print "the ".$section_name;
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.