PHP code example of timothyjensen / acf-field-group-values

1. Go to this page and download the library: Download timothyjensen/acf-field-group-values library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

timothyjensen / acf-field-group-values example snippets


    

    // Replace with the name of your field group JSON.
    $field_group_json = 'group_59e226a200966.json';

    $config = json_decode( file_get_contents( PATH_TO_ACF_JSON . $field_group_json ), true );
    

    

    $acf_post_meta = get_all_custom_field_meta( get_the_ID(), $config );
    

    

    $acf_option_values = get_all_custom_field_meta( 'option', $config );
    

    

    $term_id = 'term_2';

    $acf_term_values = get_all_custom_field_meta( $term_id, $config );
    

    

    $user_id = 'user_2';

    $acf_user_values = get_all_custom_field_meta( $user_id, $config );
    

    
    // The $block variable is passed to the render callback or template.
    $data = $block['data'];

    $acf_block_data = get_structured_block_data( $data, $config );
    

    

    // Replace with the names of your field group JSONs.
    $clone_json_1 = 'group_59e226a200967.json';
    $clone_json_2 = 'group_59e226a200968.json';

    $clone_fields = [
    	json_decode( file_get_contents( PATH_TO_ACF_JSON . $clone_json_1 ), true ),
    	json_decode( file_get_contents( PATH_TO_ACF_JSON . $clone_json_2 ), true )
    ];

    $acf_post_meta = get_all_custom_field_meta( get_the_ID(), $config, $clone_fields );
    

    

    // Passing 'true' as the fourth argument will , $config, [], true );

    /* The above results in:
    'group' => [
        'group_1'  => [
            'label' => 'Group 1 Label',
            'value' => 'Group 1',
        ],
        'group_2'  => [
            'label' => 'Group 2 Label',
            'value' => 'Group 2',
        ],
        'subgroup' => [
            'subgroup1' => [
                'label' => 'Subgroup 1 Label',
                'value' => 'Subgroup 1',
            ],
            'subgroup2' => [
                'label' => 'Subgroup 2 Label',
                'value' => 'Subgroup 2',
            ],
        ],
    ]
    */
    



$results = [
    'group'            => [
        'group_1'  => 'Group 1',
        'group_2'  => 'Group 2',
        'subgroup' => [
            'subgroup1' => 'Subgroup 1',
            'subgroup2' => 'Subgroup 2',
        ],
    ],
    'repeater'         => [
        [
            'repeater_sub_field' => 'Sub Field',
            'repeater_2'         => [
                [
                    'repeater_2_subfield' => 'Level 2 subfield',
                ],
                [
                    'repeater_2_subfield' => 'Level 2 subfield',
                ],
            ],
        ],
    ],
    'flexible_content' => [
        [
            'acf_fc_layout'      => 'flex_content_type_1',
            'flex_content_field' => 'Flex content type 1',
        ],
        [
            'acf_fc_layout'      => 'flex_content_type_2',
            'flex_content_field' => 'Flex content type 2',
        ],
    ],
    // The following are cloned fields.
    'group_1'          => 'Cloned group 1',
    'subgroup'         => [
        'subgroup1' => 'Cloned subgroup 1',
        'subgroup2' => 'Cloned subgroup 2',
    ],
];