Reputation: 110
I've created an ACF option page, all went good. I created some custom fields, once again all went good. I also saved data in the fields, all went good.
I looked in the database and it was saved under wp_options
, so all went good.
Now I wan't to get the values in an php script on the backend.
Let's say my field name is field_name
.
I used get_field('field_name', 'option');
, it didn't give me anything.
I also tried get_fields();
- this gave me an array with the option fields like this:
array(3) {
["field_name"]=> array(0) { }
["field_name1"]=> bool(false)
["field_name2"]=> string(0) ""
}
So, somehow the values are empty.
I checked the database again, but they're there.
$field = get_field_object('field_879e859f07841');
var_dump(get_post_meta ( $field['key'], 'field_name'));
This gave the same empty array..
I can't figure this out.
Can someone help with figuring what's happening?
Upvotes: 1
Views: 8917
Reputation: 110
It's a long time ago since I asked this question. I'm using the plugin Timber now which I love!
You can get the values in the standard php file like this:
$context['site_copyright_info'] = get_field('copyright_info', 'options');
Timber::render('index.twig', $context); '
The plugin renders a .twig page where you easily can use the values like this:
<footer>{{copyright_info}}</footer>
thanks for contribution all!
Upvotes: 0
Reputation: 269
Please check ACF Get values
To Display a field:
<p><?php the_field('field_name', 'option'); ?></p>
To retrieve a field as a variable:
<?php
$variable = get_field('field_name', 'option');
// do something with $variable
?>
Upvotes: 3