Home Forums Backend Issues (wp-admin) View fields registered via php in the admin


View fields registered via php in the admin

  • I am registering a group of fields with php, built and exported from the ACF admin. The fields are added through a plugin, and I am considering options for adding additional fields per site. (I did see that there is a thread for this…) I’m considering the best ways to do this, and wondering if it is possible to do through the admin — but I do not see an option for displaying fields registered via php in the admin.

    Is this possible? If it were possible, would it create a conflict between the php registering fields vs the updates created through the admin?

    ACF Pro is awesome, btw, and has totally changed how I build WP sites. Thanks!!!

  • Hi @jvpdigital

    The fields that are registered via PHP won’t show up on the backend (admin page). That’s because ACF doesn’t know where the code is located (you can put the code anywhere as long as you included the file). Even if ACF know where it’s, modifying the PHP code is not a good thing to do.

    Also, creating the same field group on the backend will mostly cause issues in the future.

    I suggest you export the field group to JSON or XML export file before generating the PHP code. That way you can import it back and modify the field groups from the admin page.

    I hope this makes sense 🙂

  • Hi, i’m looking for the exact same thing.
    I created a fields using ACF in the wp-admin area, then I exported them via php.

    Later ( by mistake ) i overwritten my database, and now I can’t edit the fields in the wp-admin, only via php.

    Is there any way i can register them again, using the php code i have.
    I need this only once, later i will edit them in the wp-admin area.

  • Marko,

    The solution I eventually came up with was to export my base set of fields as a json file. In my plugin I can then import that set of json fields, then edit them in the admin at will. Here is a chunk of my code that you may find useful:

    	function update_fields_from_json(){
    		// Find local JSON directory named 'fields'
    		$dir = new DirectoryIterator( dirname(__FILE__)  . '/fields' );
            // there should only be one json file in the fields folder (in my case)
    		foreach( $dir as $file ) {
    			if ( !$file->isDot() && 'json' == $file->getExtension() ) {
    				$json = json_decode( file_get_contents( $file->getPathname() ), true );
    				// if importing an auto-json, wrap field group in array
    				if( isset($json['key']) ) {
    					$json = array( $json );
    				foreach( $json as $field_group ) {
                        // group key is in the json file
    					$existing_fields = _acf_get_field_group_by_key("group_57796a3bdfb15");
    					// if the fields don't exist in the db import them now
    						new jvp_acf_admin_notice('Adding All JVP ACF Fields');
  • Yeah thx, but not quite what i need. I need a way to generate acf admin files, and i only have my php code to work with.

    I was wondering, is there any way, for example, to generate a json file, using the php code i have, and then import them again, so they show up in the backend.

  • Honestly, the php and json are fairly similar. You could probably grab the field group code out of the php file and convert it to a json file easily with a few search & replaces.

    My original point, essentially, was that you may be better served in the long run not using php to generate the fields. The code I included is a process for inserting the fields, from a json file, via php rather than manual import in Custom Fields > Tools.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘View fields registered via php in the admin’ is closed to new replies.