Support

Account

Home Forums General Issues Custom field configuration is missing with PHP import

Solving

Custom field configuration is missing with PHP import

  • I’ve been doing my development locally using the admin panel interface for adding/editing field groups and want to move that to a production site. Using the “Generate PHP” feature in the tools section, I’m able to get the required code for my fields and then import that into my theme’s functions.php. However, on my production site, I don’t see any of my custom fields in the “Custom Fields” admin. However, any associations that I’ve made with post types do work and the fields are all there.

    Why don’t my field configuration show up in the “Custom Fields” admin?

  • Fields added using PHP do not appear in the admin to edit. If you want to be able to edit them on the site your importing them to then it must be done with JSON and import the with the ACF tool.

  • Is there a command line version of the tool to import the data?

  • Not that I know of. There have been some discussions here about auto syncing field groups, but I cannot locate them at the moment.

  • 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';
      }
    }
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Custom field configuration is missing with PHP import’ is closed to new replies.