Home › Forums › General Issues › Custom field configuration is missing with PHP import › Reply To: Custom field configuration is missing with PHP import
Okay, I came up with my own solution here. It’s very similar to the PHP export solution but just uses the same function in ACF that the JSON import uses. The code for the most part is just copied from the JSON import tool. In order to call this, I just created a special page that executes the code as long as the user is an admin.
class AcfInit
{
public static function install()
{
$json = self::jsonExport();
$json = json_decode($json, true);
// Check if empty.
if( !$json || !is_array($json) ) {
echo "Invalid data";
return;
}
// Ensure $json is an array of groups.
if( isset($json['key']) ) {
$json = array( $json );
}
// Loop over json
foreach( $json as $field_group ) {
// Search database for existing field group.
$post = acf_get_field_group_post( $field_group['key'] );
if( $post ) {
$field_group['ID'] = $post->ID;
}
// Import field group.
acf_import_field_group( $field_group );
}
echo "done!";
}
public static function jsonExport()
{
return 'JSON EXPORT CONTENTS GO HERE';
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.