Snippets

MVF ACF from PHP to JSON

Created by Calogero Guagenti
<?php

$groups = acf_get_local_field_groups();
$json = [];


foreach ($groups as $group) {
    // Fetch the fields for the given group key
    $fields = acf_get_local_fields($group['key']);

    // Remove unecessary key value pair with key "ID"
    unset($group['ID']);

    // Add the fields as an array to the group
    $group['fields'] = $fields;

    // Add this group to the main array
    $json[] = $group;
}

$json = json_encode($json, JSON_PRETTY_PRINT);

// Optional - echo the JSON data to the page
echo $json;
die;

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.