Last active
January 8, 2016 12:35
-
-
Save k1sul1/2d787dfcae7345437ed5 to your computer and use it in GitHub Desktop.
"Convert" ACF field group json dumps to php array syntax.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$json = '[{"key":"group_5533906b7cb6f","title":"Kirja-arviot","fields":[{"key":"field_54f96fb0b6afd","label":"Kirjan nimi","name":"kirja-nimi","type":"text","instructions":"","required":0,"conditional_logic":0,"wrapper":{"width":"","class":"","id":""},"default_value":"","placeholder":"","prepend":"","append":"","formatting":"html","maxlength":"","readonly":0,"disabled":0},{"key":"field_54f97431afa89","label":"Kirjan kuva","name":"kirja-kuva","type":"image","instructions":"","required":0,"conditional_logic":0,"wrapper":{"width":"","class":"","id":""},"preview_size":"thumbnail","library":"all","return_format":"array","min_width":0,"min_height":0,"min_size":0,"max_width":0,"max_height":0,"max_size":0,"mime_types":""},{"key":"field_54f9728eb6b00","label":"Kirjan tiedot","name":"kirja-tiedot","type":"repeater","instructions":"Esimerkiksi julkaisija, kirjan kuvaus tai julkaisuvuosi.","required":0,"conditional_logic":0,"wrapper":{"width":"","class":"","id":""},"row_min":"","row_limit":"","layout":"table","button_label":"Add Row","min":0,"max":0,"sub_fields":[{"key":"field_54f972a8b6b01","label":"Tieto","name":"tieto","type":"text","instructions":"","required":0,"conditional_logic":0,"wrapper":{"width":"","class":"","id":""},"default_value":"","placeholder":"","prepend":"","append":"","formatting":"html","maxlength":"","readonly":0,"disabled":0},{"key":"field_54f972ccb6b02","label":"Arvo","name":"arvo","type":"text","instructions":"","required":0,"conditional_logic":0,"wrapper":{"width":"","class":"","id":""},"default_value":"","placeholder":"","prepend":"","append":"","formatting":"html","maxlength":"","readonly":0,"disabled":0}]}],"location":[[{"param":"post_format","operator":"==","value":"aside"}]],"menu_order":0,"position":"normal","style":"seamless","label_placement":"top","instruction_placement":"label","hide_on_screen":[],"active":1,"description":""}]'; | |
$json = json_decode($json); | |
$json = $json[0]; | |
//var_dump($json->fields); | |
foreach($json->fields as $field){ | |
$acf_key = null; | |
foreach($field as $key => $value){ | |
$label = null; | |
if($key == "label"){ | |
$label = $value; | |
} | |
if($key == "key"){ | |
$acf_key = $value; | |
} | |
if(!is_null($acf_key) && !is_null($label)){ | |
echo "'$label' => '$acf_key',\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment