Important
This article shows how you can set charts data dynamically using ACF plugin, if you are not familiar with ACF, you can watch this video tutorial.
Create ACF Fields
- On your dashboard, go to Custom Fields -> click on `Add New` to create a field group, Once you have created your field group, you can start adding fields from `Add Field`. Check this for detailed description.
Put ACF Fields Together
Now, we will need to put ACF fields together in one field that we will use in our charts
- On your dashboard, go to Appearance -> Editor, on the right side, select Theme Functions `functions.php`
- Add the following code to the very end of the file:
function create_charts_field_group() {
acf_add_local_field_group(array(
‘key’ => ‘group_1’,
‘title’ => ‘Charts Group’,
‘location’ => array (
array (
array (
‘param’ => ‘post_type’,
‘operator’ => ‘==’,
‘value’ => ‘post’,
),
),
),
));
acf_add_local_field(array(
‘key’ => ‘info’,
‘label’ => ‘Person Info’,
‘name’ => ‘person_info’,
‘type’ => ‘text’,
‘parent’ => ‘group_1’
));
}
function create_charts_update_field() {
$age = get_field(‘age’);
$weight = get_field(‘weight’);
$height = get_field(‘height’);
$data = $age . ‘,’ . $weight . ‘,’ . $height;
update_field( ‘info’ , $data );
}
add_action(‘acf/init’, ‘create_charts_field_group’);
add_action(‘acf/save_post’, ‘create_charts_update_field’);